Open topic with navigation

TIBCO BusinessEvents® Enterprise Edition 6.3.1

# Limit Clause

You can use an optional `limit` clause in a `select` or an `order by` clause.

When used in a `select` clause, it limits the maximum number of rows to return. The limit clause is applied last after the all the clauses are executed on the result set.

You can also use an optional `offset` to ignore the first `n` rows.

When used in an ordered by clause, the limit applies to each of the items in the ordered list (after the ordering is executed). See Working With Implicit Windows.

## Example Showing Use in Select Clause

    select {limit: first 10 offset 20} c.name from /Customer c

Without the limit clause, this query would return all customers. With the limit, it returns 10 customers, with an offset of 20. That is, it returns customers 20-30.

## Example Showing Use in Order By Clause

The following query keeps count of the number of students per department. Every time a student enrolls or leaves, the count changes and the query produces the entire list sorted on the count, sorted in descending order, and limited to the first two.

    select s.deptName, count(*)
      from /Student s
      group by s.deptName
      order by count(*) desc {limit: first 2};

The `limit` clause specifies that only the first two of the ordered lists of departments are returned by the query: the list of departments with the largest number of students, and the list of departments with the second largest number of students.

Did you find this helpful?

YesNo
Great!
Thanks for taking the time to give us some feedback.
Sorry about that

Why wasn't this helpful? (check all that apply)

Could not find what I was looking for
Instructions confusing or unclear
Instructions did not work

Want to tell us more?

Please select at least one option or provide details about the issue!!

Error occurred while submitting feedback.

Error2 occurred while submitting feedback.

TIBCO BusinessEvents® Enterprise Edition

Copyright © 2004-2024. Cloud Software Group, Inc. All Rights Reserved.