Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select specific Columns for MAX value of a column

Status
Not open for further replies.

leo6

Programmer
Mar 2, 2005
22
US
From the given table ,
COLA COLB COLC COLD
---- ---- ---- ----
1 4 a 1
2 6 s 2
4 9 d 3
3 17 e 1
5 11 f 2
6 15 r 3

I would like to retreive,
COLA COLB COLC
---- ---- ----
3 17 e


ie., values for COLA,COLB and COLC having max value for COLB .

I know we can use,
select COLA,COLB,COLC from table
where COLB in (select max(COLB) from table )

but,is there any other way to write this query for better execution ?
 
Use = not IN.
Code:
select COLA,COLB,COLC 
from table
where COLB = (select max(COLB) from table )


Denny
MCSA (2003) / MCDBA (SQL 2000)

--Anything is possible. All it takes is a little research. (Me)

[noevil]
(My very old site)
 
No,,both = and IN are the same.I was wondering if join could be used??
 
Yes you could use a join, with an inline subquery. I don't think it will give you an performance difference.
Code:
select COLA,COLB,COLC 
from table
join (select max(COLB) colb from table) t2 on table.COLB = t2.COLB

Denny
MCSA (2003) / MCDBA (SQL 2000)

--Anything is possible. All it takes is a little research. (Me)

[noevil]
(My very old site)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top