Hi,If you want all the values from your original table, I'd try something like this:create table #sales (Salesperson varchar(10), location varchar(10), client varchar(10), salesdate datetime, sale_amount decimal (10,2))insert #salesselect 'John', 'London', 'ABC', '01/01/2009', 100.00 unionselect 'John', 'London', 'ABC', '01/02/2009', 200.00 unionselect 'John', 'Norwich', 'DEF', '01/03/2009', 312.00 unionselect 'sarah', 'Norwich', 'DEF', '01/01/2009', 250.00 unionselect 'sarah', 'Norwich', 'DEF', '01/05/2009', 100.00 unionselect 'sarah', 'London', 'ABC', '01/01/2009', 90.00 unionselect 'sarah', 'London', 'ABC', '01/02/2009', 400.00 unionselect 'fernando', 'Liverpool', 'GHI', '01/06/2009', 75.00 unionselect 'fernando', 'Liverpool', 'GHI', '01/04/2009', 100.00selects.salesperson,s.location,s.client,s.salesdate,s.sale_amountfrom #sales sjoin (select salesperson, max(sale_amount) sale_amount from #sales group by salesperson) mson s.salesperson = ms.salespersonand s.sale_amount = ms.sale_amountdrop table #sales
You create an alias table with just the max sale and the sale person in it (ms). You can then join this back to the sales table and the two values together act like a unique key.Obviously, if you have a number of maximum sales at the same value, it will bring back more rows.Cheers,Yonabout