In this lesson ,you will learn how to use the SQL LIMIT clause.
What is the SQL LIMIT Clause?
The SQL LIMIT clause allows us to limit the number of rows that are returned from a SQL query. It is useful if you only want to see a few rows from the database table to get a rough idea of what the table's layout is.
You can also use the LIMIT clause if you only need to see the data points that lie at the extremes of a data distribution, which can be done by pairing the LIMIT clause with the ORDER BY statement.
The LIMIT clause goes at the very end of a SQL query. This makes sense, because its operations (eliminated all but a certain number of rows) needs to be done after all other data manipulation.
Here is a generalized example of how the LIMIT clause fits into a SQL query:
Combining the LIMIT Clause with the ORDER BY Statement
As mentioned, combining the LIMIT clause with the ORDER BY statement is a very powerful tool for generating database rows that have extreme values for a particular column.
As an example, here is the generalized syntax for returning the 5 rows that have the highest value for column_name: