Knowee
Questions
Features
Study Tools

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: Customers.IdName1Joe2Henry3Sam4MaxTable: Orders.IdCustomerId1321Using the above tables as example, return the following:CustomersHenryMaxOptionsselect Name as Customers from Customers not in ( select CustomerId from Orders);select Name from Customers where Id in ( select CustomerId from Orders);select Name as Customers from Customers where Id not in ( Orders);select Name as Customers from Customers where Id not in ( select CustomerId from Orders);

Question

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: Customers.IdName1Joe2Henry3Sam4MaxTable: Orders.IdCustomerId1321Using the above tables as example, return the following:CustomersHenryMaxOptionsselect Name as Customers from Customers not in ( select CustomerId from Orders);select Name from Customers where Id in ( select CustomerId from Orders);select Name as Customers from Customers where Id not in ( Orders);select Name as Customers from Customers where Id not in ( select CustomerId from Orders);

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

The correct SQL query to find all customers who never order anything would be:

select Name as Customers from Customers where Id not in ( 
    select CustomerId from Orders
);

This query works by first selecting the CustomerId from the Orders table. The not in clause then checks the Id in the Customers table against this list and returns the Name of any customers whose Id is not in the list, i.e., customers who have not placed any orders.

This problem has been solved

Similar Questions

For the following tables:Customers (CustomerID, CustomerName, PhoneNumber, Address)Orders (OrderID, OrderDate, CustomerID)To return the CustomerName and OrderDate that the result must include the customers who have not placed any orders.Which Transact-SQL query should you use?SELECT CustomerName, OrderDateFROM Customers JOIN Orders ON Customers.CustomerID = Orders.CustomerID;SELECT CustomerName, OrderDateFROM Customers RIGHT OUTER JOIN OrdersON Customers.CustomerID = Orders.CustomerID;SELECT CustomerName, OrderDateFROM Customers LEFT OUTER JOIN OrdersON Customers.CustomerID = Orders.CustomerID;SELECT CustomerName, OrderDateFROM Customers CROSS JOIN OrdersON Customers.CustomerID = Orders.CustomerID;

You have a Microsoft SQL Server database that contains tables named Customers and Orders. The tables are related by a column named CustomerID. You need to create a query that meets the following requirements:1. Returns the CustomerName for all customers and the OrderDate for any orders that they have placed. 2. Results must include customers who have not placed any orders. Which Transact-SQL query should you use?

Find Customer RefereeGiven a table customer holding customers information and the referee.idnamereferee_id1WillNULL2JaneNULL3Alex24BillNULL5Zack16Mark2Write a query to return the list of customers NOT referred by the person with id'2'. For the sample data above, the result is:nameWillJaneBillZackOptionsselect namefrom customerwhere referee_id is null or referee_id <> 2;select namecustomerwhere referee_id is null or referee_id <> 2;select referee_idfrom customerwhere referee_id is null or referee_id <> 2;select namefrom customerwhere name is null or referee_id <> 2;

Find the names of the customer that are not referred by the customer with id = 2.Return the result table in any order.The result format is in the following example.

You have a sales table that has a salesAmount and a customerNumber field. You need to find the You are creating a query that will join the results of two tables. You begin typing the query:SELECT customers.firstName, customers.lastName, orders.orderDateFROM customers ______ JOIN ordersON customers.customerNumber = orders.customerNumberYou want to see all the rows from the customers table, even if they don’t have a corresponding record in the orders table.What should you type in the blank space? (Please type your answer all in upper case. Example: SELECT or UNION ALL)

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.