# 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.

SELECT
series_id,
season_id,
episode_id,
CAST(air_date AS Date) AS air_date,
title

FROM episodes
WHERE
series_id = 1      -- List of conditions to build the result
AND season_id > 1  -- Logical AND is used for complex conditions

ORDER BY              -- Sorting the results.
series_id,         -- ORDER BY sorts the values by one or multiple
season_id,         -- columns. Columns are separated by commas.
episode_id

LIMIT 3               -- LIMIT N after ORDER BY means
-- "get top N" or "get bottom N" results,
;                     -- depending on sort order.

COMMIT;