22.1. SQL Part 4 - Subqueries, UNION, INTERSECT, EXCEPT

22.1.1. Reading

The articles below share how to use subqueries in queries that go beyond a SELECT statement. We will go more in-depth on these other types of statements in the next lesson. For now, focus on the rules of subqueries.

Subqueries

Subqueries (SQL Server).

SQL - Sub Queries.

UNION, INTERSECT, EXCEPT

SQL Union, Intersect, and Except – The Ultimate Guide.

Correlated Subqueries

SQL Correlated Subqueries.

22.1.2. Check Your Understanding

Question

Every statement that uses a subquery can be re-written as a join.

  1. True
  2. False

Question

A subquery cannot use ORDER BY, but the main query can.

  1. True
  2. False

Question

Match the operator to the result set:

INTERSECT Combined rows from both queries.
EXCEPT Only keeps rows in common with both queries.
UNION Keeps rows from left query that aren’t in common with right query.

Question

UNION combines columns and joins combine rows.

  1. True
  2. False

Question

What is the difference between a correlated subquery and a nested subquery?