Back to JOINS, UNION, NULL HANDLING

JOINS - FULL, CROSS JOIN

Understand how FULL JOIN and CROSS JOIN work

10 minutesVideo LessonPDF notes
🎯 Free Guest Mode: You are learning for free. Sign in to save your completion progress and quiz answers.

Ready to continue?

Mark this lesson as complete when you're ready to proceed.

Key moments

  1. Joins and FROM ClauseJoins are SQL instructions placed in the FROM clause used to combine data sets.
  2. Primary and Foreign KeysA primary key uniquely identifies a row, while a foreign key links to another table's primary key.
  3. Joining Logic and RisksTables can be joined on any columns of the same type, but joining without foreign keys is risky.
  4. INNER JOIN (Default)INNER JOIN combines rows only when there are matching values in the specified common column.
  5. LEFT JOIN BehaviorLEFT JOIN returns all rows from the first table, using NULLs for non-matching values from the right table.
  6. RIGHT JOIN BehaviorRIGHT JOIN returns all rows from the right table, using NULLs for non-matching values from the left table.
  7. FULL JOIN (OUTER JOIN)FULL JOIN combines all data from both tables, using NULLs where matches do not exist.
  8. UNION and UNION ALLUNION stacks data vertically and deduplicates, while UNION ALL stacks data vertically and keeps duplicates.
  9. CROSS JOIN (Cartesian)CROSS JOIN combines every row of the first table with every row of the second table.
PDF notes

Frequently asked questions

Why is RIGHT JOIN rarely used in practice?

Any query written using a RIGHT JOIN can be rewritten as a LEFT JOIN, which is the more conventional and widely used standard.

What happens if I use JOIN without specifying INNER, LEFT, or RIGHT?

JOIN is the default syntax and is equivalent to an INNER JOIN, only returning rows with matches in both tables.

Do the columns used for joining have to be Primary or Foreign Keys?

No, they only need to be of the same data type, but using PK/FK ensures logical and accurate relationships.

How does UNION differ from UNION ALL?

UNION automatically removes duplicate rows from the combined result set, while UNION ALL stacks data vertically and retains all rows, including duplicates.