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

Query Help

Status
Not open for further replies.

tommyc7

Programmer
Feb 3, 2007
33
0
0
US
Hey.. I'm a developer, but my SQL is weak... Can someone please give me a hint as to how I would do the following?

Suppose the following table:

Table: AAA

Code:
Column1   Column2   Column3
-------   -------   -------
1         100       B
2         100       C
3         100       B
4         101       C
5         101       C
6         101       C


What I am trying to do is retrieve all columns in which Column2 and Column3 are distinct but have the highest possible value in column1. Assume Column1 is a key and is unique.

In this case, my query needs to return:

2 100 C
3 100 B
6 101 C

Thanks!



 
GROUP BY is used to find distinct combinations, i.e. group by column(s). MAX is used to get maximum value. Combine these two.

You may also want to check out ORDER BY.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top