Subject | Re: [ib-support] Max value |
---|---|
Author | Svein Erling Tysvaer |
Post date | 2002-12-18T11:20:26Z |
>SELECT NUMBER FROM TEST WHERE AMOUNT>=(SELECT MAX(AMOUNT) FROMWell, I suppose you can do it this way if you've only got four records in
>TEST WHERE AMOUNT<(SELECT MAX(AMOUNT) FROM TEST))
your table, but this kind of query may be very slow if there is a
substantial number of records in the table. For Firebird, the preferred
method would be SELECT FIRST 2 as someone said. If you're running some
older Interbase version, using EXISTS is also quite quick:
SELECT NUMBER FROM TEST T1
WHERE NOT EXISTS(
SELECT 1 FROM TEST T2 WHERE T2.AMOUNT > T1.AMOUNT AND EXISTS(
SELECT 1 FROM TEST T3 WHERE T3.AMOUNT > T2.AMOUNT))
Set