Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PostgreSQL Select where multiple OR statements

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)
like image 926
John Smith Avatar asked Jan 17 '14 09:01

John Smith


1 Answers

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;
like image 182
a_horse_with_no_name Avatar answered Sep 21 '22 07:09

a_horse_with_no_name