views:

75

answers:

2

hi!

As a newb, I already know that I will be berated for asking this question, but I did not find the answer on the site here and could use some help...

I have a table that lists data by the day, and by type. For example

Transaction  |  Date  | Type
-----------------------------
Updat    | 11/7/2008  | Cash-out
Update   | 11/10/2008 | Wrote-check 
Deposit  | 11/11/2009 | Cashed Check 
Update   | 11/18/2008 | Wrote check 
Deposit  | 11/19/2009 | Cashed Check


What I'm trying to do, is find the very first occurrence of each transaction type, and the very last occurrence of each transaction type. so I'm trying to figure out an sql statement that I can write that will return something like this:

Transaction  |  First Date  | Last Date  |
----------------------------------------------
Update       | 11/7/2008    | 11/18/2008 |
Deposit      | 11/11/2009   | 1/19/2009  |

any ideas?

+10  A: 
SELECT Transaction, Min([date])  AS [First Date] , Max([Date]) AS [Last Date]
FROM myTable GROUP BY Transaction
Russell Steen
+3  A: 
SELECT
     transaction,
     MIN([date]) AS [First Date],
     MAX([date]) AS [Last Date]
FROM
     My_Table
GROUP BY
     transaction
Tom H.