5
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.

user1857647
  • 49
  • 1
  • 1
  • 3

3 Answers3

5

How about this?

SELECT
    *
FROM
    Tabl tabb
WHERE
    (tabb.col1 = 1 AND tabb.col2 = 2) OR
    (tabb.col1 = 3 AND tabb.col2 = 4)
hall.stephenk
  • 1,175
  • 7
  • 10
0

You could do something like this:

SELECT *
FROM Tabl tabb
inner join (
    select 1 a, 2 b 
    union select 3, 4
) x
on tabb.col1 = x.a
and tabb.col2 = x.b
JohnLBevan
  • 22,735
  • 13
  • 96
  • 178
0

In case of numeric columns and supposing the values are bounded to a specific range more values can be packed into one number using some formula

for instance supposing the values of col1 and col2 are from 1 to 1000 the formula

  N = 10000 * col1 + col2

can be used and in the example the select would be

  SELECT * FROM Tabl tabb WHERE (10000 * tabb.col1 + tabb.col2) IN ( 10002, 30004)

In general string concatenation can be used to combine several column values, for example

  SELECT * FROM Tabl tabb WHERE (tabb.col1||"&"||tabb.col2) IN ( "1&2", "3&4")
elxala
  • 291
  • 3
  • 5