Sorting and filtering
Select the first three episodes from every season of “IT Crowd”, except the first season.
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. series_id,
3. season_id,
4. episode_id,
5. CAST(air_date AS Date) AS air_date,
6. title
8. FROM episodes
9. WHERE
10. series_id = 1 -- List of conditions to build the result
11. AND season_id > 1 -- Logical AND is used for complex conditions
13. ORDER BY -- Sorting the results.
14. series_id, -- ORDER BY sorts the values by one or multiple
15. season_id, -- columns. Columns are separated by commas.
16. episode_id
18. LIMIT 3 -- LIMIT N after ORDER BY means
19. -- "get top N" or "get bottom N" results,
20. ; -- depending on sort order.
22. COMMIT;

