LeetCode - mysql左连接习题【题175. 组合两个表+题183. 从不订购的客户】
程序员文章站
2022-04-16 14:28:40
...
题175. 组合两个表 (左连接)
思路:左连接LEFT JOIN , 右表是可能地址为空的address表。
SELECT p.FirstName,p.LastName,a.City,a.State
FROM Person AS p
LEFT JOIN Address AS a
ON p.PersonId=a.PersonId
题183. 从不订购的客户:(左连接的过滤)
思路:通过左连接显示所有客户的订单,没有订购任何东西的orders表Id为null
SELECT NAME AS Customers
FROM Customers AS c
LEFT JOIN Orders AS o
ON c.Id=o.CustomerId
WHERE o.Id IS null;