Jump to content

Quick question about MAX


kevinfwb

Recommended Posts

It's been a little bit since my SQL class so please bear with me  ;D

 

I have a table that has a list of store numbers and their sales.  I'm trying to pull the max sales and the corresponding store number.

 

I can SELECT MAX(sales) from Sales and I get the highest value.  However when I select storeNum, MAX(sales) FROM Sales I get the highest value of each pair, which is all of them. 

 

I know it has something to do with a subquery, but I don't remember the exact syntax.  I've also tried..

 

SELECT storeNum, sales FROM Sales WHERE sales=(select MAX(sales))

This query runs, I just get no results.

 

Any help is greatly appreciated.

 

-Kevin

 

**UPDATE**

 

I think I have solved my own problem.  In my originaly query, I have a where clause (WHERE WEEK = 2 AND YEAR = 2007)  I did not have that same WHERE clause in my subquery.  After adding the WHERE clause to my subquery, it seems to be working.

Link to comment
https://forums.phpfreaks.com/topic/49343-quick-question-about-max/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.