-3

hello I have this problem where I have a list of ids like

ID= 1,2,3,4,5

and the field in the database has values like

3,4,56,34,1,2,3 // field name can be users

and now I want to select all the tables in the database which has any of the values in ID

I tried this with

 FIND_IN_SET

but it's not working properly

    FIND_IN_SET (users, $ID)

can anyone help me with this, please??

Gufran Hasan
  • 8,910
  • 7
  • 38
  • 51
Amani
  • 281
  • 3
  • 15

2 Answers2

1

This should work :

$ID = "(1, 2, 3, 4, 5)";
$q = "SELECT * FROM `users` WHERE `ID` IN " . $ID;
//Execute $q here
Jean-Marc Zimmer
  • 537
  • 6
  • 20
1

like this?

SELECT * FROM `tableName` WHERE CONCAT(",", `users`, ",") REGEXP ",(1|2|3|4|5),"
suresh bambhaniya
  • 1,687
  • 1
  • 10
  • 20
  • This is actually working, but i want to get results only if all the values of ID matches with users . i tried using & insted of | but dosent works – Amani Nov 12 '18 at 09:35
  • you can store users in ascending order(1,2,3,4,34,56) and then use SELECT * FROM `tableName` WHERE `users` REGEXP "1,2,3,4,5" – suresh bambhaniya Nov 12 '18 at 09:56