skip to Main Content

Is it possible to add condition within the in clause of postgresql

for example

select ... where (t1.subject,t2.weight) in ((1,2),(2,3))

I want to check whether subject is 1 but weight can be >= 2 not just 2 and so on. So that condition would logically look somewhat like

select ... where (t1.subject,t2.weight) in ((1,>2),(2,>3))

2

Answers


  1. You can select value of object using subquery. Simple just select query subject which are having weight greater than >=2.

    select … where (t1.subject,t2.weight) in (select subject FROM … where weight >=2 ,select subject FROM … where weight >=3 );

    Login or Signup to reply.
  2. No, this is not possible. You need to write

    …
    WHERE t1.subject = 1 AND t2.weight > 2
       OR t1.subject = 2 AND t2.weight > 3;
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search