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 q
SELECT * FROM table WHERE id IN (1, 2, 3 etc)
And call only the columns you need rather than using *
!
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
1
ifexpr
is equal to any of the values in theIN
list, else returns0
.
....
WHERE id IN (3, 9, 100, ...)
$sql = "SELECT name FROM artists WHERE id REGEXP regex-pattern"
You can use SQL IN condition
SELECT * FROM table WHERE ID IN ('1', '2', '3', '4');
SELECT * FROM table WHERE id IN (1,2,5);