I have the following PgSQL query, in which i'm looking where user_id equals any one of a set of id's i am looking for.
Question is, is there a way to simply the statement so that I dont have to keep putting user_id= ?
SELECT *
FROM comments
WHERE session_id=1
AND (user_id=10 OR user_id=11
OR user_id=12 OR user_id=13
OR user_id=14 OR user_id=15
OR user_id=16)
SELECT *
FROM comments
WHERE session_id=1
AND user_id in (10,11,12,13,14,15,16);
alternatively for this specific case:
SELECT *
FROM comments
WHERE session_id=1
AND user_id between 10 and 16;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With