Domanda

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

È stato utile?

Soluzione

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
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top