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

Trouble gleaning distincts, all fields same except one 2

Status
Not open for further replies.

Soiboy

Programmer
Jul 22, 2002
16
US
I am getting technically distinct records since one of the fields is different, but I don't want all of them, just the one with the largest number in it.

Here is an example of what my current sql statement is returning:

field1, field2, field3
apple, fruit, 50
apple, fruit, 43
apple, fruit, 32
orange, round, 56
orange, round, 43
orange, round, 31

I want to return the first (largest number) of each, so it returns:
apple, fruit, 50
orange, roound, 56


thanks,

Ed
 
select field1,field2,max(field3)
from table
group by field1,field2

“I sense many useless updates in you... Useless updates lead to fragmentation... Fragmentation leads to downtime...Downtime leads to suffering..Fragmentation is the path to the darkside.. DBCC INDEXDEFRAG and DBCC DBREINDEX are the force...May the force be with you" --
 
Select field1,field2,max(field3)
from <table>
Group by field1,field2
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top