SQL语句,用两个键嵌套在查询中

时间:2013-05-06 19:47:31

标签: sql sql-server

SELECT * FROM TAB1 WHERE (ID1,ID2) IS IN (SELECT ID1,ID2 FROM TAB2)

ID1和ID2是TAB1和TAB2的两个主键, 我们可以用单个主键来完成它但是如何处理2个主键

1 个答案:

答案 0 :(得分:2)

SELECT  *
FROM    tab1
WHERE   EXISTS
        (
        SELECT  NULL
        FROM    tab2
        WHERE   tab2.id1 = tab1.id1
                AND tab2.id2 = tab1.id2
        )