加入消除嵌套查询

时间:2013-10-23 01:07:14

标签: sql

如何将下面的查询重写为消除嵌套查询的连接。

SELECT Company, State2 
FROM Customers
WHERE Id IN 
   (SELECT CustomerId 
    FROM Orders 
    WHERE ((ShipDate BETWEEN '2004-01-1'AND'2004-12-31')AND(Shipping>5.0)));

1 个答案:

答案 0 :(得分:0)

SELECT  DISTINCT a.Company,
        a.State2 
FROM    Customers a
        INNER JOIN Orders b
            ON a.Id = b.CustomerId
WHERE   b.ShipDate BETWEEN '2004-01-01' AND '2004-12-31'
        AND b.Shipping > 5.0

要进一步了解联接,请访问以下链接: