Sunday, February 19, 2012

Help Required - Selecting the last transaction for a client..

Hi all,
Happy New Year!!!
I have a table that has the following fields:
Client, Date
Data:
Microsoft, 1/1/05
Microsoft, 2/2/05
IBM, 3/8/05
HP, 2/4/05
HP, 2/5/05
How do I construct a query so that the results are:
Microsoft, 2/2/05
IBM, 3/8/05
HP, 2/5/05
Thus it is only giving me the last transaction or most recent transaction
for each client.
Your help is greatly appreciated.
ClintClint (ccpatriot12@.yahoo.com) writes:
> I have a table that has the following fields:
> Client, Date
> Data:
> Microsoft, 1/1/05
> Microsoft, 2/2/05
> IBM, 3/8/05
> HP, 2/4/05
> HP, 2/5/05
> How do I construct a query so that the results are:
> Microsoft, 2/2/05
> IBM, 3/8/05
> HP, 2/5/05
> Thus it is only giving me the last transaction or most recent transaction
> for each client.
SELECT Client, MAX(Date)
FROM tbl
GROUP BY Client
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx|||Thanks!
Worked perfectly.

No comments:

Post a Comment