10

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)

1 Answer 1

26
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;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.