Customers Who Never OrderSuppose 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 where Id not in ( select CustomerId from Orders);select 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);
Question
Customers Who Never OrderSuppose 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 where Id not in ( select CustomerId from Orders);select 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);
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 selecting the names of customers from the Customers table where the Id of the customer is not found in the list of CustomerIds in the Orders table. This effectively returns the names of customers who have never placed an order.
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 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.
Query the customer_number from the orders table for the customer who has placed the largest number of orders.It is guaranteed that exactly one customer will have placed more orders than any other customer.The orders table is defined as follows:ColumnTypeorder_number (PK)intcustomer_numberintorder_datedaterequired_datedateshipped_datedatestatuschar(15)commentchar(200)Sample Inputorder_numbercustomer_numberorder_daterequired_dateshipped_date112017-04-092017-04-132017-04-12222017-04-152017-04-202017-04-18332017-04-162017-04-252017-04-20442017-04-182017-04-282017-04-25Sample Outputcustomer_number3ExplanationThe customer with number '3' has two orders, which is greater than either customer '1' or '2' because each of them only has one order.So the result is customer_number '3'. Follow up: What if more than one customer have the largest number of orders, can you find all the customer_number in this case?Optionsselect customer_numberfrom ( select customer_number, count(*) as cnt from orders group by customer_number) as eorder by e.cnt desclimit 1;select customer_number select customer_number, count(*) as cnt from orders group by customer_number) as eorder by e.cnt desclimit 1;select customer_numberfrom ( select customer_number, count(*) as cnt from orders group by customer_number) as elimit 1;select customer_numberfrom ( select customer_number, count(*) as cnt group by customer_number) as eorder by e.cnt desclimit 1;
Orders table got below attributesOrder_no, Custnbr, Product, Qty, Amt, DiscountCustomers table got below attributesCustnbr, Company, Custrep, CreditlimPrint the Order_no, Amt, Company and creditlim of the customers who placed orders. Select Order_no, Amt, Company, Creditlim from Customers outer join Orders on customers.custnbr=orders.custnbrSelect Order_no, Amt, Company, Creditlim from Customers left outer join Orders on customers.custnbr = orders.custnbrSelect Order_no, Amt, Company, Creditlim from Customers inner join Orders on customers.custnbr = orders.custnbrSelect Order_no, Amt, Company, Creditlim from Customers right outer join Orders on customers.custnbr = orders.custnbr
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.