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;
- Gita, 70; Hari, 90; Isha, 80; Jay, 60
- Gita, 70; Hari, 90; Jay, 60; Isha, 80
- Hari, 90; Gita, 70; Isha, 80; Jay, 60
- 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
- A query is written as SELECT emp_name FROM Staff UNION SELECT trainee_name…
- Table MondaySale: item Tea Samosa Tea Vada Table TuesdaySale: item Samosa Poha…
- Table Employee: id | name 1 | Kavya 2 | Lokesh Table Intern: id | name |…
- Table Store: city | product Pune | Pen Pune | Ink Table Depot: city | product…
- Table Cricket: student Aman Bina Chetan Bina Table Football: student Bina…
- Table Cricket: student Aman Bina Chetan Bina Table Football: student Bina…
- Table SectionA: name | marks Gita | 70 Hari | 90 Table SectionB: name | marks…
- Table Customer(cust_id, name) has 5 rows and table Supplier(supp_id, name) has…
- Table Cricket: student Aman Bina Chetan Bina Table Football: student Bina…
- Table MayOrders: order_id | coupon 1 | SAVE10 2 | NULL 3 | NULL Table…
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