You want to limit the number of rows returned by a query. We have 239 rows of data in this table and want to show only 5 rows of data from it.
MySQL and PostgreSQL –
To limit the number of rows in MySQL and PostgreSQL, you can use the LIMIT clause.
SELECT * FROM country LIMIT 5
SQL Server –
In SQL Server, you can use the TOP keyword to limit the number of rows returned.
SELECT TOP 5 * FROM country
In DB2 use the FETCH FIRST clause.
SELECT * FROM country FETCH FIRST 5 ROWS ONLY
In Oracle, you can use the ROWNUM in the WHERE clause to limit the number of rows returned.
SELECT * FROM country WHERE ROWNUM <= 5
Related Post – Randomly select data from a SQL Table.
if you like this post then share it with others and subscribe to our blog below to learn more about SQL.