Skip to content
Advertisement

How to select by two fields using IN operator

I tried query like

SELECT id FROM events WHERE iid = 2 AND target_id = 3 OR iid = 3 AND target_id = 5 OR...

How to short this? Also tried to use IN operator but it get wrong logic

SELECT id FROM events where iid IN (2, 3) AND target_id IN (3, 5)

Advertisement

Answer

Postgres support tuples equality:

select id
from events
where (iid, target_id) in ( (2, 3), (3, 5) )
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement