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. It takes one or two arguments. You can specify a very big integer for row_count to output 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

  • offset : Specify the offset value of the starting row to be output. 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 : Specify the number of records to be output. 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  'Laura'                         2           500

          301  'Max'                           4           300

          501  'Chang'                         5           150

          501  'Sue'                           6           150

 

--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  'Laura'                         2           500

          301  'Max'                           4           300

          501  'Chang'                         5           150