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

Était-ce utile?

La 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
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top