I'm trying to grab content where id = 3 OR id = 9 OR id = 100... Keep in mind, I can have a few hundred of these ids.
What is the most efficient way to write my query?
$sql = "SELECT name FROM artists WHERE (id=3 OR id=9 OR .... id-100)"
I'm trying to grab content where id = 3 OR id = 9 OR id = 100... Keep in mind, I can have a few hundred of these ids.
What is the most efficient way to write my query?
$sql = "SELECT name FROM artists WHERE (id=3 OR id=9 OR .... id-100)"
You may want to use the IN() function:
... WHERE id IN (3, 9, 100);
The IN() function syntax:
expr IN (value,...)Check whether a value is within a set of values ...
Returns
1ifexpris equal to any of the values in theINlist, else returns0.
You can use SQL IN condition
SELECT * FROM table WHERE ID IN ('1', '2', '3', '4');