如何使用in运算符按两个字段进行选择

carvr3hs  于 2021-07-26  发布在  Java
关注(0)|答案(1)|浏览(348)

我试着问

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

如何缩短这个?也尝试过在运算符中使用,但逻辑错误

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

rkttyhzu1#

postgres支持元组相等:

select id
from events
where (iid, target_id) in ( (2, 3), (3, 5) )

相关问题