-4

I have a table subcontractor, it has a column manager and on manager values are stored like '1,2,3,4,5,6,11,12,13,15'

I want to get all subcontractors that have manager id 2 in subcontractor table.

Dharman
  • 26,923
  • 21
  • 73
  • 125
  • You use `IN` method of mysql also – A.A Noman Dec 31 '21 at 09:41
  • 2
    [Is storing a delimited list in a database column really that bad?](https://stackoverflow.com/questions/3653462/is-storing-a-delimited-list-in-a-database-column-really-that-bad) – Alon Eitan Dec 31 '21 at 09:43

1 Answers1

1

You can use the find_in_set function:

SELECT *
FROM   subcontractor
WHERE  FIND_IN_SET('2', managers) > 0
Mureinik
  • 277,661
  • 50
  • 283
  • 320
  • This will give the right result, but it will have poor performance as the table grows. Using a function to search in this way cannot be optimized using an index. – Bill Karwin Dec 31 '21 at 15:24