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.

7. FROM
8. seasons AS sa
9. INNER JOIN
10. series AS sr
11. ON sa.series_id = sr.series_id
12. WHERE sa.series_id = 1
13. ORDER BY                         -- Sorting of the results.
14. sr.series_id,
15. sa.season_id                 -- ORDER BY sorts the values by one column
16. ;                                -- or multiple columns.
17. -- Columns are separated by commas.

19. COMMIT;

Joining tables with JOIN - 图1