Using tuples in SQL “IN” clause

前端 未结 8 1095
刺人心
刺人心 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 04:57

    You can use a common table expression to pretend that these tuples are in another table:

    ;WITH Tuples as (
         select '1234-567' as group_id, 2 as group_type union all
         select '4321-765', 3 union all
         select '1111-222', 5
    )
    SELECT * /* TODO - Pick appropriate columns */
    from mytable m where exists (
       select * from Tuples t
       where m.group_id = t.group_id and m.group_type = t.group_type)
    

提交回复
热议问题