6

We have an Interbase 7.1 database and I'm trying to figure out how to limit the number of records returned by the query to just 1. I really only need to know an event code from the last record, in which the query will return hundreds of records if I cannot do some kind of limit.

Thanks in advance!

Dragn1821
  • 777
  • 2
  • 7
  • 19

2 Answers2

13

I think I figured it out. Needed to do something like this...

SELECT * FROM table ORDER BY col ROWS 1
TarangP
  • 2,560
  • 5
  • 18
  • 35
Dragn1821
  • 777
  • 2
  • 7
  • 19
6

As per the accepted answer:

SELECT * FROM table ORDER BY col ROWS 1

Will return just one result. There are also several other row limiting options available:

ROWS n        Returns the first n rows of the result set, or n percent if used with PERCENT
ROWS m TO n   Returns rows m through n, inclusive or the mth to nth percent
ROWS n BY p   Returns every pth row of the first n rows

This is particularly handy for paged results.

From the Embedded SQL Guide on the InterBase Product Documentation page:

aboy021
  • 1,782
  • 1
  • 19
  • 23