Open Source RDBMS - Seamless, Scalable, Stable and Free

한국어 | Login |Register

Versions available for this page: CUBRID 8.3.0 |  CUBRID 8.3.1 |  CUBRID 8.4.0 |  CUBRID 8.4.1 |  CUBRID 8.4.3 |  CUBRID 9.0.0 | 

LIMIT Clause

Description

The LIMIT clause can be used to limit the number of records displayed. You can specify a very big integer for row_count to display to the last row, starting from a specific row. The LIMIT clause can be used as a prepared statement. In this case, the bind parameter (?) can be used instead of an argument.

INST_NUM() and ROWNUM cannot be included in the WHERE clause in a query that contains the LIMIT clause. Also, LIMIT cannot be used together with FOR ORDERBY_NUM() or HAVING GROUPBY_NUM(). 

Syntax

LIMIT { [offset,] row_count | row_count [ OFFSET offset ] }

  • offset: Specifies the offset value of the starting row to be displayed. The offset value of the starting row of the result set is 0; it can be omitted and the default value is 0.
  • row_count: Specifies the number of records to be displayed. You can specify an integer greater than 0.
Example

--LIMIT clause can be used in prepared statement

PREPARE STMT FROM 'SELECT * FROM sales_tbl LIMIT ?, ?';

EXECUTE STMT USING 0, 10;

 

--selecting rows with LIMIT clause

SELECT * FROM sales_tbl

WHERE sales_amount > 100

LIMIT 5;

      dept_no  name                  sales_month  sales_amount

==============================================================

          201  'George'                        1           450

          201  'George'                        2           250

          201  'Laura'                         2           500

          301  'Max'                           1           300

          301  'Max'                           2           300

 

--LIMIT clause can be used in subquery

SELECT t1.* FROM

(SELECT * FROM sales_tbl AS t2 WHERE sales_amount > 100 LIMIT 5) AS t1

LIMIT 1,3;

      dept_no  name                  sales_month  sales_amount

==============================================================

          201  'George'                        2           250

          201  'Laura'                         2           500

          301  'Max'                           1           300