Bird
0
0

Which of the following is the correct syntax to combine two SELECT queries with UNION and sort the final result by column name?

easy📝 Syntax Q12 of 15
SQL - Set Operations
Which of the following is the correct syntax to combine two SELECT queries with UNION and sort the final result by column name?
ASELECT name FROM table1 UNION ORDER BY name SELECT name FROM table2;
BSELECT name FROM table1 ORDER BY name UNION SELECT name FROM table2;
CSELECT name FROM table1 UNION SELECT name FROM table2 ORDER BY name;
DSELECT name FROM table1 UNION SELECT name FROM table2 SORT BY name;
Step-by-Step Solution
Solution:
  1. Step 1: Understand correct UNION syntax

    The UNION combines two SELECT queries; ORDER BY applies after the last SELECT.
  2. Step 2: Check placement of ORDER BY

    ORDER BY must come after the entire UNION, not between or before queries.
  3. Final Answer:

    SELECT name FROM table1 UNION SELECT name FROM table2 ORDER BY name; -> Option C
  4. Quick Check:

    ORDER BY after UNION = A [OK]
Quick Trick: Place ORDER BY after all UNION queries [OK]
Common Mistakes:
MISTAKES
  • Putting ORDER BY before UNION
  • Using SORT BY instead of ORDER BY
  • Placing ORDER BY between SELECTs

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes