Bird
0
0

Consider two tables:

medium📝 query result Q5 of 15
SQL - Set Operations
Consider two tables:
Orders1:
order_id | product
101 | Book
102 | Pen
103 | Notebook

Orders2:
order_id | product
102 | Pen
103 | Notebook
104 | Pencil

What is the output of:
SELECT order_id, product FROM Orders1 INTERSECT SELECT order_id, product FROM Orders2;
Aorder_id | product 102 | Pen 103 | Notebook
Border_id | product 101 | Book 102 | Pen 103 | Notebook 104 | Pencil
Corder_id | product 101 | Book
Dorder_id | product 104 | Pencil
Step-by-Step Solution
Solution:
  1. Step 1: Find rows present in both Orders1 and Orders2

    Rows with order_id 102 (Pen) and 103 (Notebook) exist in both tables.
  2. Step 2: INTERSECT returns these common rows

    Only these rows appear in the result.
  3. Final Answer:

    order_id | product 102 | Pen 103 | Notebook -> Option A
  4. Quick Check:

    INTERSECT output = common rows only [OK]
Quick Trick: INTERSECT returns rows common to both SELECT queries [OK]
Common Mistakes:
MISTAKES
  • Including all rows from both tables
  • Returning rows only from first table
  • Returning rows only from second table

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes