How does 'LIMIT' parameter work in sql?

后端 未结 6 1269
余生分开走
余生分开走 2020-12-14 17:52

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?

6条回答
  •  旧巷少年郎
    2020-12-14 18:42

    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:

    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:

提交回复
热议问题