Re: SQL Question
Posted in 1997
Tin Zaw wrote:
>
> Does any one know how to do following in SQL (Informix in particular)?
>
> I need to get the first row a SELECT statement finds, not all the rows.
>
> e.g. SELECT * from my_table where row_value < 10 ....
>
> should return first row with row_value < 10, even the table has
> many qualifying rows.
>
> A cc: will be much appreciated.
>
> TIA.
> --
> Tin Zaw x.13205 mailto: tzaw@qualcomm.com
> Network Engineer QUALCOMM Inc. www.qualcomm.com
Hi Tin,
hoy do you determine the "first" row? Supposed you want a query that returns
1 row only (not minding which one), you could use a cursor and only fetch the
first row. Another option is using a subselect with rowids (could be different
in 7.x - I heard of different treatement of rowids there) like in:
SELECT * FROM my_table WHERE row_value < 10 AND rowid =
(SELECT MIN(rowid) FROM my_table WHERE row_value < 10)
Ciao, Peter
============================
Peter Kolmhofer
Database Engineer
Porsche Informatik Austria
email: kop@porsche.co.at