Bird
0
0

Which of the following is the correct syntax to find common rows between two tables TableA and TableB with the same columns id and name?

easy📝 Syntax Q12 of 15
SQL - Set Operations
Which of the following is the correct syntax to find common rows between two tables TableA and TableB with the same columns id and name?
ASELECT id, name FROM TableA JOIN TableB ON TableA.id = TableB.id;
BSELECT id, name FROM TableA UNION SELECT id, name FROM TableB;
CSELECT id, name FROM TableA INTERSECT SELECT id, name FROM TableB;
DSELECT id, name FROM TableA WHERE id IN TableB;
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct INTERSECT syntax

    The INTERSECT operator is used between two SELECT statements with matching columns and types.
  2. Step 2: Check each option

    SELECT id, name FROM TableA INTERSECT SELECT id, name FROM TableB; uses INTERSECT correctly. SELECT id, name FROM TableA UNION SELECT id, name FROM TableB; uses UNION which combines rows. SELECT id, name FROM TableA JOIN TableB ON TableA.id = TableB.id; uses JOIN which is different. SELECT id, name FROM TableA WHERE id IN TableB; has incorrect WHERE syntax.
  3. Final Answer:

    SELECT id, name FROM TableA INTERSECT SELECT id, name FROM TableB; -> Option C
  4. Quick Check:

    Correct INTERSECT syntax = SELECT id, name FROM TableA INTERSECT SELECT id, name FROM TableB; [OK]
Quick Trick: Use INTERSECT between two SELECTs with matching columns [OK]
Common Mistakes:
MISTAKES
  • Using UNION instead of INTERSECT
  • Trying to use WHERE with IN incorrectly
  • Confusing JOIN with INTERSECT

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes