Re: how can i find out the second maximum value from a table by sql

From: Ashish Mittal <mittalashish_at_yahoo.com>
Date: Sun, 17 Feb 2002 08:26:01 GMT
Message-ID: <tOJb8.70706$fK1.4191838_at_rwcrnsc54>


Yes, I suspect it would. Provided you table is indexed, a MUCH fater query may be

select max(col) from table where col < (select max(col) from
table);

"Pablo Sanchez" <pablo_at_dev.null> wrote in message news:VI2b8.147$FG2.395386_at_news.uswest.net...
>
> "Ken Papai" <ken_at_kenpapai.com> wrote in message
> news:BRVa8.13713$kt5.29586_at_rwcrnsc52.ops.asp.att.net...
> >
> > "keith" <prk25_at_yahoo.com> wrote ...
> > > sohelcsc_at_yahoo.com (Leader) asked:
> > > > How can i find out the second maximum value from a table by sql
> > > >
> > > > thanks
> > > > Hoque
 

> > > select max(col) from table where col != (select max(col)
 from
> > table);
> >
> > PERFECT and best answer by Keith.
>
> Wondering aloud, would the outer 'select' result in a table scan?
> --
> Pablo Sanchez, High-Performance Database Engineering
> www.hpdbe.com
> Available for short-term and long-term contracts
>
>
Received on Sun Feb 17 2002 - 09:26:01 CET

Original text of this message