What if we set a LIMIT value that is greater than the total number of rows?


#1

Question

In SQL, what happens if we set a LIMIT value that is greater than the total number of rows?

Answer

If the number set in the LIMIT clause surpasses the number of rows available to select, then it will just exclude the remaining amount of rows in the result set.

You might think of LIMIT as an upper bound for the number of rows to return, but not as a strict number of rows that must be returned.

Example

/* 
Say the table `name` has only 90 rows. 
Then, since 100 is greater than the number of rows, 
it will just return what rows are there. 
*/

SELECT *
FROM names
LIMIT 100;