Using tuples in SQL “IN” clause

前端 未结 8 1091
刺人心
刺人心 2020-11-28 04:30

I have a table containing the fields group_id and group_type and I want to query the table for all the records having any tuple (group id, group type) from

8条回答
  •  無奈伤痛
    2020-11-28 05:07

    Using that solution, this should work:

    SELECT *
    FROM mytable m
    WHERE EXISTS (
       SELECT * FROM (
       SELECT "1234-567" group_id, 2 group_type UNION ALL
       SELECT "4321-765", 3 UNION ALL
       SELECT "1111-222", 5) [t]
       WHERE m.group_id = t.group_id AND m.group_type = t.group_type) 
    

    BTW, you should probably use a CTE to create that inner table.

提交回复
热议问题