Back to JOINS, UNION, NULL HANDLING

JOINS - INNER, LEFT AND RIGHT

Understand combining data from multiple tables using INNER/LEFT/RIGHT JOINS

18 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. Introduction to JoinsJoins combine tables using a common column, which must share similar data.
  2. Inner Join SyntaxAn inner join returns only rows that have matching values in both tables.
  3. Resolving AmbiguityWhen columns share the same name, they must be qualified using the table name to avoid errors.
  4. Using Table AliasesAliases provide short nicknames for tables, simplifying column qualification and improving readability.
  5. Qualifying SELECT ColumnsAmbiguous columns must also be qualified in the SELECT statement to specify the source table.
  6. Left Join OperationA left join returns all rows from the left table and only matching rows from the right table.
  7. Right Join OperationA right join returns all rows from the right table and only matching rows from the left table.
  8. Self Join ConceptA self join links a table to itself, requiring distinct aliases to differentiate the two instances.
  9. Self Join Use CaseBy joining on EMP1.ID + 1 = EMP2.ID, rows can be related sequentially for assignments.
  10. Joining Multiple TablesMultiple joins are chained sequentially, ensuring each adjacent pair shares a common column for linkage.
PDF notes

Frequently asked questions

Is JOIN the same as INNER JOIN?

Yes, JOIN is the default syntax and implicitly performs an inner join, but explicitly writing INNER JOIN is clearer.

Why do I get an "ambiguous column" error?

This happens when a column name appears in both tables and SQL doesn't know which one to select or reference. You must qualify the column name with the table or alias.

Why are aliases necessary if I can just use the full table name?

Aliases save significant typing, especially when qualifying many columns, and make the query much easier to read and maintain.

What happens to the columns from the non-matching table in a LEFT or RIGHT join?

The columns corresponding to the rows that did not find a match will be populated entirely with NULL values.