Bird
0
0

You have two tables:

hard📝 Application Q8 of 15
SQL - Set Operations
You have two tables:

Table Products:
product_id INT, product_name VARCHAR, price DECIMAL

Table Sales:
sale_id INT, product_name VARCHAR, amount DECIMAL

You want to combine product_name and price/amount columns from both tables using UNION. Which query is correct?
ASELECT product_name, price FROM Products UNION SELECT sale_id, amount FROM Sales;
BSELECT product_id, product_name FROM Products UNION SELECT sale_id, product_name FROM Sales;
CSELECT product_name, price FROM Products UNION SELECT product_name FROM Sales;
DSELECT product_name, price FROM Products UNION SELECT product_name, amount FROM Sales;
Step-by-Step Solution
Solution:
  1. Step 1: Identify columns to combine

    We want product_name and price/amount columns from both tables.
  2. Step 2: Check column counts and types

    SELECT product_name, price FROM Products UNION SELECT product_name, amount FROM Sales; selects two columns from each table with compatible types (VARCHAR and DECIMAL).
  3. Final Answer:

    SELECT product_name, price FROM Products UNION SELECT product_name, amount FROM Sales; -> Option D
  4. Quick Check:

    Matching columns and types = C [OK]
Quick Trick: UNION columns must match in count and compatible types [OK]
Common Mistakes:
MISTAKES
  • Mixing unrelated columns
  • Mismatching column counts
  • Ignoring data type compatibility

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes