UNION, INTERSECT & EXCEPT · Question 10 · Medium

Table SectionA: name | marks Gita | 70 Hari | 90 Table SectionB: name | marks Isha | 80 Jay | 60 What does this query return?

SELECT name, marks FROM SectionA
UNION ALL
SELECT name, marks FROM SectionB
ORDER BY marks DESC;
  1. Gita, 70; Hari, 90; Isha, 80; Jay, 60
  2. Gita, 70; Hari, 90; Jay, 60; Isha, 80
  3. Hari, 90; Gita, 70; Isha, 80; Jay, 60
  4. Hari, 90; Isha, 80; Gita, 70; Jay, 60
Answer and explanation

Answer: D. Hari, 90; Isha, 80; Gita, 70; Jay, 60

Explanation: An ORDER BY written after the last SELECT of a UNION sorts the whole combined result, not just the second query. All four rows are therefore sorted by marks from high to low.

Previous: Table Employee: id | name 1 | Kavya 2 | Lokesh Table Intern: id | name |… · Next: Table Store: city | product Pune | Pen Pune | Ink Table Depot: city | product…

Practise union, intersect & except

Try a fresh set of union, intersect & except questions with an explanation after every answer, free and without signing up: UNION, INTERSECT & EXCEPT practice. Or sit a full placement mock test.

More union, intersect & except questions

More sql practice

Tables, Keys & Constraints · DML & Transactions · SELECT, WHERE & ORDER BY · SQL Joins · Aggregates & GROUP BY · Subqueries & CTEs · Window Functions · NULL Handling

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge