How does 'LIMIT' parameter work in sql?

Viewed 31403

I have 4000 rows for example, and I define X limit.

The query stops after it finds X rows? or the query finds all the rows and then takes X rows from the found rows?

Thank you.

6 Answers

Introduction to MySQL LIMIT clause

The following illustrates the LIMIT clause syntax with two arguments:

SELECT 
select_list
FROM
table_name
LIMIT [offset,] row_count;
  • The offset specifies the offset of the first row to return. The offset of the first row is 0, not 1.
  • The row_count specifies the maximum number of rows to return.

The following picture illustrates the LIMIT clause:

enter image description here

Therefore, these two clauses are equivalent:

> LIMIT row_count; 
> LIMIT 0 , row_count;

The following picture illustrates the evaluation order of the LIMIT clause in the SELECT statement:

enter image description here

Related