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 10This will return the top 10 records.
Challenge
EasyAvailable 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 10This returns the top 10 records from the table.
Try it yourself
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Fundamentals
4More Keywords
The IN keywordThe BETWEEN keywordThe LIKE keywordThe AS keywordRecap - Cellphone Models2Conditions
Conditions BasicsThe AND keywordThe OR keywordThe NOT keywordMultiple Conditions CombinedParenthesisBooleans5Arithmetic Operations
Mathematical OperatorsMathematical ColumnsThe Modulo OperationThe ROUND() Function3Specific Return Format
Null valuesSort Results Part 1Sort Results Part 2Recap - Cyber Security FirmLimit number of recordsRecap - Vehicle Factory6Intro Challenges
Recap - Parliamentary ElectionRecap - Police Criminal ArrestRecap - Bar Beverage ContainerRecap - Engineer new columns