Joining tables with JOIN

Merge the columns of the source tables seasons and series, then output all the seasons of the IT Crowd series to the resulting table using the JOIN operator.

Note

We assume that you already created tables in step Creating a table and populated them with data in step Adding data to a table.

  1. SELECT
  2. sa.title AS season_title, -- sa and sr are "join names",
  3. sr.title AS series_title, -- table aliases declared below using AS.
  4. sr.series_id, -- They are used to avoid
  5. sa.season_id -- ambiguity in the column names used.
  6. FROM
  7. seasons AS sa
  8. INNER JOIN
  9. series AS sr
  10. ON sa.series_id = sr.series_id
  11. WHERE sa.series_id = 1
  12. ORDER BY -- Sorting of the results.
  13. sr.series_id,
  14. sa.season_id -- ORDER BY sorts the values by one column
  15. ; -- or multiple columns.
  16. -- Columns are separated by commas.
  17. COMMIT;

Joining tables with JOIN - 图1