Re: SQL TRICK. Select rowid, max(...)
Posted in 1994
doctorq@sam (DoctorQ Komputery i Programy) writes:
>Dima Rasnitsyn (rasnitsn@milcse.rtsg.mot.com) wrote:
>: Hi!
>: Could anybody suggest me some SQL trick for selecting rowid of row with a max
>: value in some column?
>: I want to do
>: SELECT rowid, max (col1)
>: FROM mytable
>: WHERE <my conditions>
>Try this:
>SELECT rowid, col1
^^^^^^ you need to include any ORDER BY column in the
SELECT (I KNOW you knew that, I'm nit picking!)
>FROM mytable
>WHERE <my conditions>
>ORDER BY col1 DESC
>And then fetch one row !
>It runs, and it runs fast.
>Michal Hobot
>doctorQ Computers
>doctorq@sam.nask.com.pl
============================================================
Dennis J. Pimple Senior Consulting Services Engineer
Informix Software Inc Denver Colorado USA
dennisp@informix.com Voice:303-850-0210 Fax:303-779-4025