?
Solved

How do I find highest prices for each manufacturer in database

Posted on 2005-04-18
3
Medium Priority
?
232 Views
Last Modified: 2010-03-19
Hi, I have a table with the following columns:

1. ProductID
2. Price
3. Manufacturer

for example:

203    $500   Samson
454    $1000  Samson
100    $800    Ricardos
203    $1200  Ricardos
501    $50      Chambers

What I need to do is group the information in such a way that returns the top price (in descending order) for each manufacturer and the ProductID for that price - so in the above example, this would be returned:

$1200 203 Ricardos
$1000 454 Samson
$50     501 Chambers

Can anyone please help with the sql query? I have tried grouping, but once I get to add the ProductID column, I get all the results rather than only the top price for each Manufacturer in the table.

Thanks
0
Comment
Question by:georgep7
3 Comments
 
LVL 15

Accepted Solution

by:
Colosseo earned 500 total points
ID: 13811109
How about this

Don't have SQL here so I am afraid that I cant test it for you beforehand

This assumes that your table is called products so you will probably have to change it

SELECT p.Price, p.ProductID, p.Manufacturer
FROM products AS p
WHERE p.Price=(SELECT MAX(price) FROM products p2 WHERE p2.Manufacturer = p.Manufacturer)
ORDER BY p.Price DESC

HTH

Scott
0
 

Author Comment

by:georgep7
ID: 13811231
Hi Scott, your query only returns one manufacturer - this is what I tried (putting your query exactly as written with my table names didn't work, so note the slight variation)

SELECT tProducts.Price, tProducts.SerialNumber, tProducts.Manuf
FROM tProducts
WHERE Price=(SELECT MAX(Price) FROM tProducts WHERE Manuf = Manuf)
ORDER BY Price DESC
0
 
LVL 28

Expert Comment

by:rafrancisco
ID: 13811485
Colosseo's statement should work.  You forgot to put back the aliases of the tables (p and p2).  Its important that those are there.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Suggested Courses

616 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question