Friday, May 7, 2021
More

    Customers Who Never Order

    Must Read

    Programmerhttp://www.improgrammer.net
    We started this site to inspire young minds to motivate and encourage them towards Programming Language. In this site you will get programming tutorials, tech, programming facts, programming fun and programming blogs.

    Suppose that a website contains two tables, the tableCustomers and the tableOrders. Write a SQL query to find all customers who never order anything.

    Table: Customers.

    +----+-------+
    | Id | Name  |
    +----+-------+
    | 1  | Joe   |
    | 2  | Henry |
    | 3  | Sam   |
    | 4  | Max   |
    +----+-------+
    

    Table: Orders.

    +----+------------+
    | Id | CustomerId |
    +----+------------+
    | 1  | 3          |
    | 2  | 1          |
    +----+------------+
    

    Using the above tables as an example, return the following:

    +-----------+
    | Customers |
    +-----------+
    | Henry     |
    | Max       |
    +-----------+

     


    Solution :

    SELECT Name as Customers 
    FROM Customers WHERE Id not in (select CustomerId from Orders)

     

    Latest Articles

    More Recipes Like This