0

I have a row in my sql table that look like this

I would like to run query with find_in_set like this:

list
------------
1,2,5,33,3,4

SELECT * FROM mytable WHERE FIND_IN_SET( id, list ) 

and get the position of the result in a new field

oded
  • 155
  • 1
  • 4
  • 16

1 Answers1

1

FIND_IN_SET() returns the position of the id value in the list, so:

SELECT *,
       FIND_IN_SET( id, list ) as position
  FROM mytable 
 WHERE FIND_IN_SET( id, list )

or

SELECT *,
       FIND_IN_SET( id, list ) as position
  FROM mytable 
 HAVING position > 0
Mark Baker
  • 209,507
  • 32
  • 346
  • 385