Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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)
share|improve this question
add comment

1 Answer

up vote 4 down vote accepted
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;
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.