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.
Example 1:
Table: Customers Table: Orders+----+-------+ +----+------------+| Id | Name | | Id | CustomerId |+----+-------+ +----+------------+| 1 | Ram | | 1 | 3 || 2 | Shyam | | 2 | 1 || 3 | Sheeta| +----+------------+| 4 | Geeta |+----+-------+Output: Customers Who never order+-----------+| Customers |+-----------+| Shyam || Geeta |+-----------+
Approach:
Mysql
select name as Customersfrom Customers where id not in (select CustomerId from Orders);
Oracle
select name as Customersfrom Customers where id not in (select CustomerId from Orders);
No comments:
Post a Comment