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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select only 1 raw each for a product 2

Status
Not open for further replies.

dnagahawatte

Programmer
Jan 12, 2006
7
GB
Dear support;
If i have a prodyct table with different product instances with the same product name and all those instances have a different price; How can i only select product instances with the highest price.
Product / Name / Price
Car - BMW £10000
Car - MB £15000
Car - VW £7000
Computer - IBM £500
Computer - DELL £250
Computer - HP £750

Out come should be
Car - MB £15000
Computer - HP £750

Thanks
 
Thanks,yes it should be
I didn't do in QA so I couldn't test it
So this is the correct answer

select p.product,p.name,p.price from
product p join (select max(price) as Maxprice,product
from product
group by product ) pp on p.product =pp.product and p.price =pp.Maxprice


Denis The SQL Menace
SQL blog:
Personal Blog:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top