Re: How to get the first row in a selection of rows
Posted in 2003
Have you tried this
Select first 1 <cols>
into ...
from <table>
where <where clause>
"Andrew Hardy"
<Andrew.Hardy@mar To: informix-list@iiug.org
coni.com> cc:
Sent by: Subject: How to get the first row in a selection of rowS
owner-informix-li
st@iiug.org
15/10/2003 05:00
I have a select statement whch retrieves a number of rows. Given the
underlying condition, I want the fastest way just to get the first of the
selected rows.
Andrew H.
Detail
===========================================================================================
I create a cursor 'userFileRead_nextOidCursor' based on the folloing SELECT
select {+INDEX(user_file_read_table, oid_index)} oid, f2, f3, f4 from
user_file_read_table
where oid > x order by oid
Then I get just the next ( i.e. the first ) row.
EXEC SQL FETCH NEXT userFileRead_nextOidCursor INTO :the_oid, v2, v3, v4
Then I close the cursor.
Can I do this faster ? May be it would be faster in one statement ?
The best I can think of so far is two statements.
select {+INDEX(user_file_read_table, oid_index)} MIN(oid) into required_oid
from user_file_read_table where oid > x
select {+INDEX(user_file_read_table, oid_index)} oid, f2, f3, f4 into
the_oid, v2, v3, v4 from user_file_read_table where oid = required_oid
Any suggestions. Speed is my main priority. But may be its as fast as it
can be with the cursor.
sending to informix-list
sending to informix-list