UNION, INTERSECT & EXCEPT · Question 9 · Medium
Table Employee: id | name 1 | Kavya 2 | Lokesh Table Intern: id | name | college 7 | Manav | NIT Trichy What happens when this query runs?
SELECT id, name FROM Employee
UNION
SELECT id, name, college FROM Intern;
- It returns 3 rows, with NULL in the college column for employees
- It fails, because the two SELECTs return a different number of columns
- It returns 3 rows, silently dropping the college column
- It returns only the Intern row, because it has the most columns
Answer and explanation
Answer: B. It fails, because the two SELECTs return a different number of columns
Explanation: The first SELECT returns 2 columns and the second returns 3. A set operator needs the same number of columns on both sides, so the statement is rejected; SQL does not pad or drop columns for you.
Previous: Table MondaySale: item Tea Samosa Tea Vada Table TuesdaySale: item Samosa Poha… · Next: Table SectionA: name | marks Gita | 70 Hari | 90 Table SectionB: name | marks…
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
- Two queries are known to have no rows in common, and neither has duplicates…
- 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 SectionA: name | marks Gita | 70 Hari | 90 Table SectionB: name | marks…
- 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…
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