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;
  1. It returns 3 rows, with NULL in the college column for employees
  2. It fails, because the two SELECTs return a different number of columns
  3. It returns 3 rows, silently dropping the college column
  4. 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

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