Free Practice Quiz Question List

4 SQL Joins Online Quiz Questions

Use this free practice quiz with 30 questions to review 4 SQL Joins, test your knowledge, and prepare for your next test or exam.

30 questions
01
Choose one
1 point

Given employees(employee_id, name, department_id) and departments(department_id, department_name), which ON condition matches employees to their departments using the stated key relationship?

  1. A

    ON employees.employee_id = departments.department_id

  2. B

    ON employees.department_id = departments.department_id

  3. C

    ON employees.name = departments.department_name

  4. D

    ON employees.department_id = departments.department_name

02
Choose one
1 point

A query uses FROM employees AS e JOIN departments AS d ON e.department_id = d.department_id. An employee has no matching department. What happens to that employee's row?

  1. A

    It keeps every employee and fills department columns with NULL when unmatched.

  2. B

    It keeps every department and fills employee columns with NULL when unmatched.

  3. C

    It returns only employees and departments whose department IDs match.

  4. D

    It returns every possible employee-department pair.

03
Choose one
1 point

You need a result that includes every employee, even employees without a matching department. Which join setup meets that requirement?

  1. A

    Use employees AS e LEFT JOIN departments AS d with the department-ID match condition.

  2. B

    Use employees AS e INNER JOIN departments AS d with the department-ID match condition.

  3. C

    Use employees AS e RIGHT JOIN departments AS d with the department-ID match condition.

  4. D

    Use employees AS e CROSS JOIN departments AS d.

04
Choose one
1 point

Using employees AS e and departments AS d, which approach returns only employees who have no matching department?

  1. A

    Use INNER JOIN and WHERE d.department_id IS NOT NULL.

  2. B

    Use LEFT JOIN and WHERE e.department_id IS NULL.

  3. C

    Use FULL OUTER JOIN and WHERE d.department_id IS NOT NULL.

  4. D

    Use LEFT JOIN and WHERE d.department_id IS NULL.

05
Choose one
1 point

For A RIGHT JOIN B ON A.key = B.key, what happens to a row in B that has no matching row in A?

  1. A

    Every row from the left table remains, with right-side columns set to NULL for unmatched rows.

  2. B

    Every row from the right table remains, with left-side columns set to NULL for unmatched rows.

  3. C

    Only matching row pairs remain.

  4. D

    Every possible pair of rows is returned.

06
Choose one
1 point

You need matched records plus unmatched records from both input tables. Which join type should you use?

  1. A

    It returns only matching pairs.

  2. B

    It preserves all rows from the left table but discards unmatched right rows.

  3. C

    It preserves all rows from both tables and uses NULL for columns on an unmatched side.

  4. D

    It returns every possible pair, whether or not the keys match.

07
Choose one
1 point

A products table has 8 rows and a sizes table has 5 rows. How many rows does products CROSS JOIN sizes return?

  1. A

    40 rows

  2. B

    13 rows

  3. C

    8 rows

  4. D

    5 rows

08
Choose one
1 point

Given orders(order_id, customer_id), customers(customer_id, name), order_lines(order_id, product_id, quantity), and products(product_id, product_name), which set of join conditions connects each order to its customer and its line-item products?

  1. A

    Join orders to products on order_id, then customers to order_lines on customer_id.

  2. B

    Join orders to customers on order_id, then order_lines to products on order_id.

  3. C

    Join orders to order_lines on product_id, then order_lines to products on order_id.

  4. D

    Join orders to customers on customer_id, orders to order_lines on order_id, and order_lines to products on product_id.

09
Choose one
1 point

An order has three matching rows in order_lines. A query joins orders to order_lines on order_id. How can that order appear in the result?

  1. A

    The order must appear only once because order_id is unique in orders.

  2. B

    The order can appear on multiple result rows, one per matching order line.

  3. C

    The join discards all but the first matching order line.

  4. D

    The join produces every product for that order, even products not in its order lines.

10
Choose one
1 point

A query uses employees AS e LEFT JOIN departments AS d ON e.department_id = d.department_id, followed by WHERE d.department_name = 'Sales'. Why might this fail to retain employees with no matching department, and how can the query be adjusted if those employees must remain?

  1. A

    The WHERE condition makes the join preserve more unmatched employees.

  2. B

    The query becomes a cross join because the filter refers to the right table.

  3. C

    The WHERE condition removes NULL-extended rows; moving the restriction into ON can preserve unmatched employees.

  4. D

    The filter has no effect on rows where d.department_name is NULL.

11
Choose one
1 point

You want every employee in the result, but you want only Sales departments to match. Where should you put the department-name restriction?

  1. A

    Put d.department_name = 'Sales' in the ON condition and keep the LEFT JOIN.

  2. B

    Keep the LEFT JOIN, but put d.department_name = 'Sales' in a WHERE condition.

  3. C

    Change the join to INNER JOIN and put d.department_name = 'Sales' in the ON condition.

  4. D

    Change the join to CROSS JOIN and put d.department_name = 'Sales' in the ON condition.

12
Choose one
1 point

Why might a query that joins two tables use SELECT e.name, d.department_name instead of SELECT *?

  1. A

    It forces unmatched rows to be excluded.

  2. B

    It automatically removes duplicate result rows.

  3. C

    It changes the join into an inner join.

  4. D

    It makes the result easier to interpret and avoids unnecessary or duplicate-named columns.

13
Choose one
1 point

Given employees(employee_id, name, department_id) and departments(department_id, department_name), which condition matches an employee to the referenced department?

  1. A

    Match employees.employee_id to departments.department_id.

  2. B

    Match employees.department_id to departments.department_id.

  3. C

    Match employees.name to departments.department_name.

  4. D

    Match employees.department_id to departments.department_name.

14
Choose one
1 point

A query uses INNER JOIN to connect employees with departments. What happens to an employee whose department_id has no matching row in departments?

  1. A

    Every employee, with NULL department fields for employees without a match.

  2. B

    Every department, with NULL employee fields for departments without a match.

  3. C

    Only employees and departments whose rows satisfy the join condition.

  4. D

    Every possible employee-department pair.

15
Choose one
1 point

The query starts with employees LEFT JOIN departments. If one employee has no matching department, how is that employee represented in the result?

  1. A

    Every employee remains; right-table columns are NULL when no department matches.

  2. B

    Every department remains; left-table columns are NULL when no employee matches.

  3. C

    Only employees with a matching department remain.

  4. D

    Every possible employee-department pair is returned.

16
Choose one
1 point

In employees RIGHT JOIN departments, which unmatched rows are guaranteed to remain?

  1. A

    Only matching rows remain, with no NULL values.

  2. B

    Every employees row remains, whether or not it matches.

  3. C

    Every row from both tables remains, whether or not it matches.

  4. D

    Every departments row remains; left-table columns are NULL when no employee matches.

17
Choose one
1 point

You need a result that retains every row from both employees and departments, including rows with no match. Which join type meets this requirement?

  1. A

    Only matched rows from the two tables.

  2. B

    Matched rows and unmatched rows from both tables, with NULLs on the missing side.

  3. C

    All rows from the left table, but no unmatched rows from the right table.

  4. D

    Every possible pair of rows, whether or not the join condition matches.

18
Choose one
1 point

A products table has 4 rows and a sizes table has 3 rows. How many rows does products CROSS JOIN sizes return?

  1. A

    7 rows

  2. B

    1 row

  3. C

    12 rows

  4. D

    4 rows

19
Choose one
1 point

An order query uses orders, customers, order_lines, and products. Which set of join relationships correctly follows the schema described for these tables?

  1. A

    Join orders to customers on customer_id, orders to order_lines on order_id, and order_lines to products on product_id.

  2. B

    Join orders to customers on order_id, orders to order_lines on product_id, and order_lines to products on customer_id.

  3. C

    Join orders to customers on product_id, orders to order_lines on customer_id, and order_lines to products on order_id.

  4. D

    Join every table to customers using customer_id, without conditions for the other relationships.

20
Choose one
1 point

An order has three matching rows in order_lines. When the query joins orders to order_lines, how many result rows represent that order?

  1. A

    One row, because each order can appear only once in a join result.

  2. B

    Two rows, because the order is represented once for the order and once for its lines.

  3. C

    Four rows, because the order row is repeated in addition to its three lines.

  4. D

    Three rows, one for each matching order line.

21
Choose one
1 point

A query uses employees LEFT JOIN departments, then filters with WHERE departments.department_name = 'Sales'. What happens to employees with no matching department?

  1. A

    It retains all employees because the query uses LEFT JOIN.

  2. B

    It removes employees without a matching department, so the unmatched left rows do not survive.

  3. C

    It turns all unmatched department values into the text 'Sales'.

  4. D

    It adds all departments with no employees to the result.

22
Choose one
1 point

You want every employee to remain in the result, but you want only matching departments named 'Sales' to be included. Where should the department-name restriction go?

  1. A

    Put the restriction in WHERE and add DISTINCT so unmatched employees remain.

  2. B

    Replace LEFT JOIN with INNER JOIN and filter in ON.

  3. C

    Put the department-name restriction in ON so employees without a qualifying match remain with NULL department fields.

  4. D

    Use CROSS JOIN and filter out employees after the join.

23
Choose one
1 point

Both joined tables have a column named department_id. What is a characteristic of writing the join condition as USING (department_id)?

  1. A

    It matches on the shared column and returns one copy of that matching column.

  2. B

    It returns two copies of the shared column, one from each table.

  3. C

    It creates every possible pair of rows and ignores the shared column.

  4. D

    It keeps only rows that have no match.

24
Choose one
1 point

Why is selecting named columns often preferable to SELECT * in a query that joins tables?

  1. A

    SELECT * guarantees that matching rows are not duplicated.

  2. B

    SELECT * automatically changes an outer join into an inner join.

  3. C

    Explicit columns prevent one-to-many relationships from producing repeated rows.

  4. D

    Naming the needed columns makes the result easier to interpret and avoids unnecessary or duplicate-named columns.

25
Choose one
1 point

Given employees and departments joined on employees.department_id = departments.department_id, what does an INNER JOIN return?

  1. A

    It returns every employee and fills department columns with NULL when there is no match.

  2. B

    It returns only employee-department row pairs that satisfy the join condition.

  3. C

    It returns every possible employee-department pair.

  4. D

    It returns every department, including those without employees.

26
Choose one
1 point

A products table has 3 rows and a sizes table has 4 rows. How many rows does products CROSS JOIN sizes return?

  1. A

    3

  2. B

    7

  3. C

    12

  4. D

    24

27
Choose one
1 point

A report must include every employee and every department, including employees without a department match and departments without employees. Which join behavior meets this requirement?

  1. A

    Keep all rows from both tables; use NULLs for columns from the side without a match.

  2. B

    Keep only rows with matches in both tables.

  3. C

    Keep all rows from the left table but discard unmatched rows from the right table.

  4. D

    Return every possible pair of rows from the two tables.

28
Choose one
1 point

Using employees AS e and departments AS d, which approach returns employees who have no matching department?

  1. A

    Use an inner join and filter with d.department_id IS NULL.

  2. B

    Use a right join and filter with e.department_id IS NULL.

  3. C

    Use a cross join and filter with d.department_id IS NULL.

  4. D

    Use a left join and filter with d.department_id IS NULL.

29
Choose one
1 point

An order has three matching rows in order_lines. In a query joining orders to order_lines, why might the order's details appear on three result rows?

  1. A

    The join removes the order whenever it has more than one line.

  2. B

    The query creates one row for every customer, regardless of orders.

  3. C

    Each matching order line contributes a result row, so the order details repeat.

  4. D

    The join combines all order lines into one result row automatically.

30
Choose one
1 point

You need every employee to remain in the result, but only want a right-table row to match when it meets an additional condition. Where should you put that right-table restriction?

  1. A

    Put the restriction in WHERE; it preserves all unmatched left rows.

  2. B

    Put the restriction in ON; this restricts right-side matches while preserving unmatched left rows.

  3. C

    Replace the left join with an inner join; it retains unmatched employees.

  4. D

    Put the restriction in SELECT; this changes which right-side rows match.