Menu
CoddyTech

Limit number of records

Part of the Fundamentals section of Coddy's SQL journey. Lesson 16 of 72.

Let's assume we fetched a lot of data. Sometimes we only need the top 5 or the top 10 records.

To limit the number of records we can use the LIMIT keyword

For example

SELECT *
FROM table1
LIMIT 10

This will return the top 10 records.

LIMIT always comes last. When the query also sorts, put it after ORDER BY:

SELECT *
FROM table1
ORDER BY col1
LIMIT 10
challenge icon

Challenge

Easy

Available tables and columns:

  • temperature: place_id, avg_temp

Fetch the 5 coldest places from the temperature table. Follow these steps:

  • Sort the result in ascending order
  • Limit the result to 5 rows

Try it yourself

quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals

Practice on your own: SQL playground