查询没有买单顾客的名字

在这里插入图片描述


# select Name as Customers from Customers
#  where Customers.Id not in (select CustomerId from Orders )

将两张表左连接,显示CustomerId为空的名字
# select Name as Customers from Customers
#  left join Orders on Customers.Id = Orders.CustomerId
#  where CustomerId is NULL

将两张表右连接,和上面左连接思路相反
# select Name as Customers from Customers c where c.Id not in (select Customers.Id from Customers right join Orders on Customers.Id = Orders.CustomerId)

猜你喜欢

转载自blog.csdn.net/weixin_43332500/article/details/88386104