Customers with no Orders

If I have a Customer Table and an Order Table with CustomerIds how should my Sql statement be constructed to give me Customers with no Orders.

SELECT CustomerId /, .../
FROM Customer C
WHERE NOT EXISTS(SELECT * FROM Order O WHERE O.CustomerId = C.CustomerId)

2 Likes

hi

hope this helps

another way

SELECT 
     Columns 
FROM 
   Customer a
       LEFT JOIN 
   Orders b	
      ON  a.customerid = b.customerid
WHERE 
    b.customerid is null