Top 50 best sellers query problem??

Goalie35

New member
Local time
Yesterday, 23:00
Joined
Jan 18, 2005
Messages
5
I have to display the top 50 best sellers and order them from the highest profit to the lowest. I think my query is close but it's still not quite right.

I have 2 tables: products & orderItems.
"products" contains two fields that I need: catalogId (primary key) & productName.
"orderItems" contains a listing of every item we've ever sold. It also has two fields I need: catalogId (foreign key) & unitPrice.

Ok, so here's my query:
-----------------------------------------------------------
select top 50 sum(orderItems.unitPrice) as profit, products.productName as name from orderItems
inner join products on products.catalogid = orderItems.catalogid
group by products.catalogid
order by profit
-------------------------------------------------------------

The "SUM" function is working correctly. I've already verified it. It seems to correctly group the productName with it's corresponding profit however, for some reason, the "order by" isn't working and I'm display 602 records instead of only 50.

Any recomendations?

Thanks.

-Goalie35
 
Basically take the TOP 50 out of that query, and have it create records for everything. Then create a new TOP 50 query and base it off of that one.
 

Users who are viewing this thread

Back
Top Bottom