Monday, February 11, 2019

SQL question challenge (Customer with no orders)

SQL Challenge
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.

Table: Customer.

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

Using the above tables as example, return the following:

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

DDL SCRIPTS



create table customer (id int,name varchar(100))
insert into customer values(1,'Joe');
insert into customer values(2,'Henry');
insert into customer values(3,'Sam');
insert into customer values(4,'Max');

create table orders(id int,customer_id int);
insert into orders values(1,3);
insert into orders values(3,1);

 
solution

select cust.name from customer cust
 left join orders ord on cust.id=ord.id
 where ord.id is null;

5 comments:

  1. any case, it additionally implies more open doors for the business to demonstrate significant elements like shopper conduct, taking into account increasingly exact perspectives on circumstances and dangers. ExcelR Data Science Courses

    ReplyDelete
  2. Very interesting blog. Many blogs I see these days do not really provide anything that attracts others, but believe me the way you interact is literally awesome.You can also check my articles as well.

    Data Science In Banglore With Placements
    Data Science Course In Bangalore
    Data Science Training In Bangalore
    Best Data Science Courses In Bangalore
    Data Science Institute In Bangalore

    Thank you..

    ReplyDelete
  3. Very nice blogs!!! i have to learning for lot of information for this sites…Sharing for wonderful information.Thanks for sharing this valuable information to our vision. You have posted a trust worthy blog keep sharing, data sciecne course in hyderabad

    ReplyDelete
  4. Excellent article. Very interesting to read. I really love to read such a nice article. Thanks! keep rocking Best data science courses in hyerabad

    ReplyDelete
  5. Incredibly in general very intriguing post. I was looking for such an information and took pleasure in scrutinizing this one. Keep posting. An obligation of appreciation is all together for sharing.data analytics course in Hyderabad

    ReplyDelete