How do I limit the number of records returned for Interbase 7.1?
Question
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!
Solution
I think I figured it out. Needed to do something like this...
SELECT * FROM table ORDER BY col ROWS 1
OTHER TIPS
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:
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow