Bird
0
0

Which of the following SQL queries correctly uses a JOIN to get all customers and their orders?

easy📝 Syntax Q12 of 15
SQL - Subqueries
Which of the following SQL queries correctly uses a JOIN to get all customers and their orders?
ASELECT customers.name, orders.id FROM customers JOIN orders ON customers.id = orders.customer_id;
BSELECT customers.name, orders.id FROM customers WHERE customers.id = orders.customer_id;
CSELECT customers.name, orders.id FROM customers, orders WHERE customers.id == orders.customer_id;
DSELECT customers.name, orders.id FROM customers JOIN orders ON customers.customer_id = orders.id;
Step-by-Step Solution
Solution:
  1. Step 1: Check JOIN syntax

    Correct JOIN syntax uses ON with matching keys: customers.id = orders.customer_id.
  2. Step 2: Validate each option

    SELECT customers.name, orders.id FROM customers JOIN orders ON customers.id = orders.customer_id; uses correct JOIN and ON condition. SELECT customers.name, orders.id FROM customers WHERE customers.id = orders.customer_id; uses WHERE without JOIN, which is invalid here. SELECT customers.name, orders.id FROM customers, orders WHERE customers.id == orders.customer_id; uses double equals (==) which is invalid in SQL. SELECT customers.name, orders.id FROM customers JOIN orders ON customers.customer_id = orders.id; reverses keys incorrectly.
  3. Final Answer:

    SELECT customers.name, orders.id FROM customers JOIN orders ON customers.id = orders.customer_id; -> Option A
  4. Quick Check:

    Correct JOIN syntax = SELECT customers.name, orders.id FROM customers JOIN orders ON customers.id = orders.customer_id; [OK]
Quick Trick: JOIN uses ON with matching keys, not WHERE or == [OK]
Common Mistakes:
MISTAKES
  • Using WHERE instead of ON for JOIN condition
  • Using == instead of = in SQL
  • Mixing up key columns in ON clause

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes