1

我有一个not in这样的子句查询:

select * 
FROM COMPANY c 
where c.company_id not In (SELECT SenderId 
                            FROM CrossRef) 
  and c.id not in (select company_id 
                    FROM USER)

我想知道是否有办法在 SQL Server 2008 中使用左连接重写该查询。

我尝试了以下一个,但它没有给出正确的结果

select c.id, c.company_id 
from COMPANY c 
left join CrossRef cr on c.company_id != cr.senderid, COMPANY c1 
left join USER u on c1.id != u.company_id
4

1 回答 1

6
SELECT *
FROM Company C
LEFT JOIN CrossRef R ON R.SenderID = C.CompanyID
LEFT JOIN [User] U ON U.company_id = C.id
WHERE R.SenderID IS NULL
  AND U.company_id IS NULL
于 2013-11-08T19:02:44.980 回答