0

My Table Look like Below, Please refer Screenshot.Table Example Structure

I want a query to get the "id" when I pass the comma separated values (ex:25,10,3) in WHERE Condition of user_id column.

EX: Select id from table where user_id IN('25,10,3')

When I execute the above query I should get ID's 1 and 2.

I tired with "WHERE IN" and "find_in_set()". But nothing worked out...

Please help me to get this done...

2 Answers2

0

Balachander, find_in_set will work (see SQLFiddle), but you should reconsider using proper database structure.

slaakso
  • 8,331
  • 2
  • 16
  • 27
  • find_in set works when its select * from test where find_in_set(35,user_id);.... But I need something like this select * from test where find_in_set(35,100,25,user_id); – Balachander May 25 '17 at 09:58
  • For that you need to fix your table structure. Create a table with id, user_id and put each user_id as separate row. – slaakso May 25 '17 at 17:44
0

Finally I have Find a Solution for this....

select * from test where user_id REGEXP '(^|,)(25|10|3)(,|$)'

Refer SQLSQLFiddle