[Leet Code] Customers Who Never Order

+-------------+---------+
| Column Name | Type |
+-------------+---------+
| id | int |
| name | varchar |
+-------------+---------+
id is the primary key column for this table.
Each row of this table indicates the ID and name of a customer.

Table: Orders

+-------------+------+
| Column Name | Type |
+-------------+------+
| id | int |
| customerId | int |
+-------------+------+
id is the primary key column for this table.
customerId is a foreign key of the ID from the Customers table.
Each row of this table indicates the ID of an order and the ID of the customer who ordered it.

Write an SQL query to report all customers who never order anything.

Return the result table in any order.

The query result format is in the following example.

[틀린 쿼리]

SELECT Customers.name FROM Customers
left join Orders on Customers.id=Orders.id
where Orders.customerID=NULL

[정답 쿼리]


SELECT name as customers FROM Customers AS C
LEFT JOIN Orders AS O ON C.ID=O.CustomerID
where O.CustomerID is null 

포인트
쿼리 작성 시 null 값은 ~~is null 이라 해야함 ( a = null x)
두 테이블에서 조인으로 입력할 부분 확실하게 알기

좋은 웹페이지 즐겨찾기