-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
  • 30,962
  • 25
  • 85
  • 135
  • 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
  • 297,002
  • 52
  • 306
  • 350
  • 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