Lucas de Roo Lucas de Roo - 2 years ago 82
SQL Question

Get multiple records with one string

I have 4 rows in my database. They all got a different id starting at 1.

i have a string with multiple id's.

$str = "1,2,3,4";

How can i get all the records with id 1,2,3 and 4?

SELECT * FROM table_name WHERE id = $str

Thanks in advance.

Answer Source

try this:

SELECT * FROM table_name WHERE id IN ($str)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download