Bird
0
0

Given these tables:

medium📝 query result Q13 of 15
SQL - Table Relationships
Given these tables:
Customers(CustomerID, Name)
Orders(OrderID, CustomerID, Amount)
What will this query return?
SELECT Customers.Name, COUNT(Orders.OrderID) AS OrderCount FROM Customers LEFT JOIN Orders ON Customers.CustomerID = Orders.CustomerID GROUP BY Customers.Name;
AList of customers who have placed at least one order
BList of customers with total amount spent on orders
CList of orders with customer names repeated for each order
DList of customers with the number of orders each placed, including customers with zero orders
Step-by-Step Solution
Solution:
  1. Step 1: Understand the LEFT JOIN usage

    LEFT JOIN keeps all customers, even those without matching orders.
  2. Step 2: COUNT(Orders.OrderID) counts orders per customer

    Grouping by customer name counts how many orders each customer has, zero if none.
  3. Final Answer:

    List of customers with the number of orders each placed, including customers with zero orders -> Option D
  4. Quick Check:

    LEFT JOIN + COUNT = all customers with order counts [OK]
Quick Trick: LEFT JOIN + COUNT counts all, including zero matches [OK]
Common Mistakes:
MISTAKES
  • Thinking COUNT counts total amount spent
  • Assuming only customers with orders appear
  • Confusing JOIN types and their effects

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes