Question

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

Was it helpful?

Solution

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top