SQL Server: Selecting the first row in a GROUP BY group

1152645 pts.
Tags:
SQL Server
SQL Server database
I'm trying to select the first row of each set of rows grouped with a "GROUP BY" in a SQL Server database. Here's what my table looks like:
> SELECT * FROM purchases:
id | customer | total
 1 | Joe      | 5
 2 | Sally    | 3
 3 | Joe      | 2
 4 | Sally    | 1
So, now I'm trying to query the "ID of the largest purchase made by each individual customer, like this:
> SELECT FIRST(id), customer, FIRST(total)
. FROM purchases
. GROUP BY customer
. ORDER BY total DESC;
FIRST(id) | customer | FIRST(total)
        1 | Joe      | 5
        2 | Sally    | 3
Any help would be greatly appreciated.
0

Answer Wiki

Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.

Following

Share this item with your network: