您有2个表客户和黑名单,都有列名字和姓氏。
您如何找到好客户?请注意,由于字符限制,我无法将姓氏附加或连接到名字(反之亦然)。
我认为左连接可行。请确认。
select c.lastname,c.firstname
from Curtomers c
left join Blacklist b
ON (c.lastname = b.lastname
AND c.firstname = b.lastname)
where b.firstname is null
and b.lastname is null
答案 0 :(得分:2)
SELECT c.*
FROM Customer c
WHERE NOT EXISTS (
SELECT *
FROM Blacklist b
WHERE c.firstname = b.firstname
AND c.lastname = b.lastname
)
我认为你推断一个不在blacklist
表中的“好顾客”?另外,我不知道你正在使用什么dbms。
答案 1 :(得分:1)
SELECT *
FROM Customers C
LEFT OUTER JOIN Blacklist BL ON C.firstname = BL.firstname AND
C.lastname = BL.lastname
WHERE BL.firstname IS NULL
答案 2 :(得分:1)
怎么样
SELECT c.*
FROM Customers c LEFT JOIN
BlackList b ON c.FirstName = b.FirstName AND c.LastName = b.LastName
WHERE b.FirstName IS NULL
看看JOINS的这个漂亮的视觉表现
答案 3 :(得分:0)
select *
from customers
minus
select *
from blacklist