Bird
0
0

You have two tables:

hard📝 Application Q15 of 15
SQL - Advanced Joins
You have two tables:
Products with 4 rows and Colors with 5 rows.
You want to generate a list of all product-color combinations but exclude combinations where the product is discontinued.
Which query correctly uses CROSS JOIN and filtering?
ASELECT p.name, c.color FROM Products p INNER JOIN Colors c ON p.discontinued = FALSE;
BSELECT p.name, c.color FROM Products p CROSS JOIN Colors c WHERE p.discontinued = FALSE;
CSELECT p.name, c.color FROM Products p CROSS JOIN Colors c ON p.discontinued = FALSE;
DSELECT p.name, c.color FROM Products p, Colors c WHERE p.discontinued = TRUE;
Step-by-Step Solution
Solution:
  1. Step 1: Use CROSS JOIN to get all combinations

    Use CROSS JOIN between Products and Colors to get every product-color pair.
  2. Step 2: Filter out discontinued products

    Apply WHERE clause to keep only products where discontinued = FALSE.
  3. Step 3: Check other options for errors

    SELECT p.name, c.color FROM Products p INNER JOIN Colors c ON p.discontinued = FALSE; uses INNER JOIN incorrectly with ON condition unrelated to join keys. SELECT p.name, c.color FROM Products p CROSS JOIN Colors c ON p.discontinued = FALSE; uses ON with CROSS JOIN, which is invalid syntax. SELECT p.name, c.color FROM Products p, Colors c WHERE p.discontinued = TRUE; filters discontinued = TRUE, opposite of requirement.
  4. Final Answer:

    SELECT p.name, c.color FROM Products p CROSS JOIN Colors c WHERE p.discontinued = FALSE; -> Option B
  5. Quick Check:

    CROSS JOIN + WHERE filters correctly [OK]
Quick Trick: Filter after CROSS JOIN with WHERE clause [OK]
Common Mistakes:
MISTAKES
  • Using ON clause with CROSS JOIN
  • Filtering with wrong discontinued value
  • Confusing INNER JOIN with CROSS JOIN usage

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes