In this Leetcode Customers Who Never Order problem solution 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.
Problem solution in Oracle.
select Name as "Customers" from Customers Left Join Orders ON Customers.Id = Orders.CustomerId where Orders.CustomerId is null;
Problem solution in Mysql.
SELECT A.Name As Customers FROM Customers A WHERE NOT EXISTS (SELECT B.CustomerId FROM Orders B WHERE B.CustomerId = A.Id)
Problem solution in TSQL.
SELECT A.Name AS Customers FROM Customers AS A LEFT JOIN Orders AS B ON A.Id = B.CustomerID WHERE B.CustomerID IS NULL
0 Comments