Menu
Coddy logo textTech

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.

challenge icon

Challenge

Easy

Available tables and columns:

  • <strong>temperature</strong>: <strong>place_id</strong>, <strong>avg_temp</strong>

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

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

Cheat sheet

To limit the number of records returned by a query, use the LIMIT keyword:

SELECT *
FROM table1
LIMIT 10

This returns the top 10 records from the table.

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