The table has rows with values:

! [enter image description here

How can I find all the rows where in the ids column there is an integer "1", so that, in this case, the output is the string c id 1.

  • Do you have a full stop between 35 and 14 there, is that normal? You may have a fractional id or instead of a comma there may be a period in the data - Mike
  • Changed the picture =) - Shevtsov Eugene

3 answers 3

select * from table where find_in_set(1,ids)>0 

BUT I strongly recommend changing the structure of the base and bringing it to Normal form . Those. create another table in which there will be separate records with id from the first table and one of the values ​​from the list. Because searching in lists, separated by commas, for relational databases is non-trivial and cannot be optimized (with any query, all records in the database are scanned)

  • Yes, I already thought so. For I still have a second table, I will simply link it to the second one by id from the first one. - Shevtsov Eugene

If I understand your question correctly, then:

 select * from table where ids like '%,1,%' or ids like '%,1' or ids like '1,%' 
     select * from table where a=1 or b=1 or c=1 
    • Obviously, I initially did not correctly formulate the question - corrected. - Shevtsov Eugene