SQL In Clause Multiple Columns

user1857647 picture user1857647 · Nov 27, 2012 · Viewed 11.4k times · Source
SELECT *
FROM Tabl tabb
WHERE (tabb.col1, tabb.col2) IN ( (1,2), (3,4))

The above works in Oracle but I am trying to run in a proprietary SQL engine which doesn't support the above query formation with multiple columns in IN.

I am trying to find combinations of 1,2 and 3,4 in the DB.

Please help me with any alternatives for achieving the above.

I am looking for ways to pass a list of values for col1 and col2 from Java at one shot, so '=' might not be an option as it might require two SQL statements for achieving the above.

Answer

hall.stephenk picture hall.stephenk · Nov 27, 2012

How about this?

SELECT
    *
FROM
    Tabl tabb
WHERE
    (tabb.col1 = 1 AND tabb.col2 = 2) OR
    (tabb.col1 = 3 AND tabb.col2 = 4)