Click here to see the full article post
select name as Customers from customers
left join orders
where orders.id is null
How about this one,but little complicate:
select c.Name as Customers from Customers c
left join Orders as o on c.Id=o.CustomerId
where o.CustomerId is null;
support vladgpt answer because where in clause run slow in real time
why my anwser is not right?
select Name As Customers from Customers c where c.Id != All(select CustomerId from Orders);
select Name as Customers from Customers c where not exists( select 1 from Orders o where o.CustomerId=c.Id )
SELECT Name AS Customers
WHERE Customers.Id NOT IN (SELECT CustomerId FROM Orders)
select Name as Customers
from Customers as c
where c.Id not in (select distinct CustomerId from Orders)
I want to know the following three solutions which one is the faster and why?
SELECT NAME AS CUSTOMERS FROM CUSTOMERS A LEFT JOIN ORDERS B ON A.ID = B.CUSTOMERID WHERE B.CUSTOMERID IS NULL;
SELECT NAME AS CUSTOMERS FROM CUSTOMERS A LEFT JOIN ( SELECT DISTINCT CUSTOMERID FROM ORDERS ) B ON A.ID = B.CUSTOMERID WHERE B.CUSTOMERID IS NULL;
SELECT NAME AS CUSTOMERS FROM CUSTOMERS WHERE ID NOT IN ( SELECT DISTINCT CUSTOMERID FROM ORDERS ) ;
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.