Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (55.6k points)

Can anyone tell me which SQL command that will find any customers who have not placed orders?

2 Answers

0 votes
by (119k points)
edited by

Here is the SQL Query to find the customers details who have not placed orders:

SELECT Customer_Name

FROM Customers

WHERE Customer.id NOT IN

                                         (SELECT person_id

                                          FROM orders)

In the above query, the inner query returns the customer ids who placed orders. The outer query returns the customer names whose ids are not in the subquery using NOT IN operator.

You can register for this SQL server training and certification program by Intellipaat to learn writing complex SQL queries.

0 votes
by (1.5k points)

As per the question, lets take customer and orders as two tables.

Select * from customer join orders on customer.customerid=orders.customerid Where order.orderid is null

Here we are joining the orders and customer tables using join. Based on common column customerid. And checking for orderid in orders table is null.

1.2k questions

2.7k answers

501 comments

693 users

Browse Categories

...