Oracle Database SQL (1Z0-071) Practice Questions

Oracle Database SQL (1Z0-071) exam preparation

Oracle Database SQL (1Z0-071) practice questions in English: 180 questions with explanations. The mock exam has 78 questions and 120 minutes.

Oracle Database SQL (1Z0-071) free question 10 / 10 · Domain 9: Using SET Operators

In the tab1 table, column n has four rows: 1, 2, 2, 3. In the tab2 table, column n has four rows: 2, 2, 3, 4. How many rows does the following SELECT statement return? SELECT n FROM tab1 INTERSECT SELECT n FROM tab2;

  1. 2 rows: 2 and 3, the values in both tables
  2. 4 rows: the rows of tab1 are returned
  3. 3 rows: 2, 2, and 3, with duplicates kept
  4. 1 row: the value that appears once in each table
Show the answer and explanation

Answer: A

Why this is correct
"Set Operators" in the SQL Language Reference says that INTERSECT returns all distinct rows selected by both queries. The values that appear in both tab1 and tab2 are 2 and 3, and 2 becomes one row once duplicates are removed. The result is two rows, 2 and 3.

Why the other options are wrong
"1 row: the value that appears once in each table" … There is no rule limiting the result to values that appear once. Two values, 2 and 3, appear in both tables, and both are returned.
"3 rows: 2, 2, and 3, with duplicates kept" … INTERSECT collapses duplicate rows into one. The value 2 is not returned as two rows.
"4 rows: the rows of tab1 are returned" … The result is not all rows of tab1; it is narrowed to the rows that also exist in tab2. 1 is not in tab2, so it is not returned.

Key takeaway
INTERSECT returns the rows that exist in both queries, with duplicates removed. A value that exists in only one of them is not returned. Trace the example: tab1 holds the distinct values 1, 2, and 3, and tab2 holds 2, 3, and 4. The values that appear in both are 2 and 3, and INTERSECT returns each of them once even though 2 appears twice in each table. A value such as 1 or 4 is dropped because it is in only one of the queries.

Go to the Oracle Database SQL (1Z0-071) practice app (10 free questions; purchase unlocks all questions)

See the full practice set