T-SQL equivalent of oracle sql where expression with multiple columns

Consider an example of Oracle SQL that works just fine:

Sample data:

SQL> create table test (a number, b number);
SQL> insert into test values(1, 1);
SQL> insert into test values(1, 2);
SQL> insert into test values(1, 3);
SQL> insert into test values(1, 4);
SQL> insert into test values(1, 5);
SQL> insert into test values(2, 1);
SQL> insert into test values(2, 2);
SQL> insert into test values(2, 3);
SQL> insert into test values(2, 4);
SQL> insert into test values(2, 5);
SQL> insert into test values(4, 1);

SQL> select * from test;

         A          B
---------- ----------
         1          1
         1          2
         1          3
         1          4
         1          5
         2          1
         2          2
         2          3
         2          4
         2          5
         4          1

Query:

SQL> select * from test where (a, b) in (select 1, 4 from dual);

         A          B
---------- ----------
         1          4

Here's the sql fiddle: http://www.sqlfiddle.com/#!4/8375e/3/0

A simple question: is there any equivalent in MS SQL above "where (a, b)"? I searched on Google, MS Docs and nothing so far ...

+5
source share
2 answers

SQL Server Table Value Constructor, , SQL Server SQL , (). , EXISTS:

:

select * from test where (a, b) in (select 1, 4 from dual);

(. SQLFiddle):

select * from test where exists (
  select * from (
    select 1, 4 -- Replace with "real" subselect
  ) t(a, b)
  where test.a = t.a and test.b = t.b
)

, , (. SQLFiddle):

with t(a, b) as (
  select 1, 4 -- Replace with "real" subselect
)
select * from test where exists (
  select * from t
  where test.a = t.a and test.b = t.b
)
+5

, sql; , a=1 and b=4 sql-, .:

select 
    * 
from 
    test 
where 
    a=1 and 
    b=4;
0

All Articles