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

max value based on two columns

Status
Not open for further replies.

JustATheory

IS-IT--Management
Feb 27, 2003
115
US
Greetings,

I'm stuck on a simple query to find max values, I'm looking for the max number in col1 based on the values in col2. I keep getting all values. I thought it was as simple as:

select max(col1), col2 from table;

I've tried subqueries with a similar result. Help is always greatly appreciated.

Thanks,
JustATheory

col1 col2
10 3333
15 3333
5 4444
6 4444
7 4444

expected result

col1 col2
15 3333
7 4444
 
Try:
Code:
SELECT col2, MAX(col1)
FROM my table
GROUP BY col2;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top