183. Customers Who Never Order

Problem

Suppose that a website contains two tables, the Customers table and the Orders table. Write a SQL query to find all customers who never order anything.
문제링크

Answer

SELECT Customers.name as Customers
FROM Customers
    LEFT JOIN Orders on Customers.ID = Orders.CustomerID
WHERE Orders.ID IS NULL
-- 대부분 LEFT JOIN 으로 해결을 하기 때문에 RIGHT JOIN은 쓰는 경우가 잘 없다.
-- LEFT JOIN = LEFT OUTER JOIN
-- 테이블 이름도 AS 로 줄여서 쓸 수 있음

0개의 댓글