mysqlwhere-clausefind-in-set

FIND_IN_SET on columns? Does it make sense?


I stumbled across a strange expression, which doesn't make sense to me at all.

SELECT * FROM `table` WHERE FIND_IN_SET('string', `column`);

Why not:

SELECT * FROM `table` WHERE `column`='string';

I thought FIND_IN_SET is used to find strings in comma-separated string lists. Are there cases where I can benefit from a "FIND_IN_SET"-column expression instead of a simple WHERE?


Solution

  • FIND_IN_SET is usually used other way around: to find a column value from comma separated parameter list as storing values in database as comma separated lists is not usually a good idea:

    select * 
    FROM `table` 
    WHERE FIND_IN_SET(`column`, '1,2,3,4,5');