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 9 / 10 · Domain 7: Displaying Data from Multiple Tables

The departments table has three rows with department_id 10, 20, and 30. The employees table has three rows with department_id 10, 10, and 20. How many rows does the following SELECT statement return? SELECT d.department_id FROM departments d LEFT OUTER JOIN employees e ON d.department_id = e.department_id;

  1. 3 rows: the number of matching pairs
  2. 9 rows: each combination of 3 rows with 3 rows
  3. 1 row: department 30, which has no matching row
  4. 4 rows: department 10 twice, 20 once, and 30 once
Show the answer and explanation

Answer: D

Why this is correct
"Joins" in the SQL Language Reference says that, in a left outer join that returns all rows of A, for rows of A that have no match in B Oracle returns the row with NULL for the columns of B. Department 10 matches two employees and gives two rows, department 20 gives one row, and department 30 has no match but stays with NULLs, one row. The total is 4 rows.

Why the other options are wrong
"3 rows: the number of matching pairs" … This counts as an inner join would, matching pairs only. A left outer join also keeps department 30, which has no match, so three rows are too few.
"1 row: department 30, which has no matching row" … A left outer join does not return only the rows without a match. It returns the matching pairs and also the left rows that have no match.
"9 rows: each combination of 3 rows with 3 rows" … That is the count when the join condition is left out. The ON clause is present, so the result is the matching pairs plus the department with no match.

Key takeaway
The number of rows of a left outer join is the number of matching pairs plus the number of left rows that found no match. No row on the left side is lost.

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

See the full practice set