Title - LIMIT SQL clause Tags - sql clause programming
LIMIT can be used to limit the number of rows in a result.
It saves screen space and makes queries run faster.
This is especially useful for large tables.
Two things to keep in mind:
- LIMIT always goes at the very end of the query.
- LIMIT is not supported in all SQL databases.
Example:
SELECT * FROM movies LIMIT 10;
Would return a maximum of 10 rows in the results.
This example combines ORDER and LIMIT to return the 3 movies with the highest IMDB rating:
SELECT * FROM movies ORDER BY imdb_rating DESC LIMIT 3;