comparison within in clause of postgresql

31 Views Asked by At

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

There are 2 best solutions below

0
Rafiya Quazi On

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 );

0
Bergi On

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;