Using tuples in SQL “IN” clause

前端 未结 8 1096
刺人心
刺人心 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:48

    EDIT: this is a dated answer, although it was the accepted answer in 2011, other answers with more upvotes reflect more recent approaches.

    Why not construct the OR statements?

    SELECT *
    FROM mytable 
    WHERE (group_id = '1234-567' and group_type = 2)
        OR (group_id = '4321-765' and group_type = 3)
        OR (group_id = '1111-222' and group_type = 5)
    

    Granted, it doesn't look as nice and neat as your concept example but it will do the job (and if you IN with tuples did exist, it would implement it exactly the same way under the covers most likely.

提交回复
热议问题