I have a table (table1):
ID INSERTDATE ISSUE SOURCE
1 2011-12-01 A EMAIL
2 2011-12-02 B POST
3 2011-12-03 C MEETING
4 2011-12-04 B INTERNET
I would like to get the latest SOURCE for each issue…
SELECT * FROM table1 GROUP BY SOURCE ORDER BY ISSUE ASC
Results in
ID INSERTDATE ISSUE SOURCE
1 2011-12-01 A EMAIL
2 2011-12-02 B POST
3 2011-12-03 C MEETING
But how can I get the following, so that issue B has the latest source?
ID INSERTDATE ISSUE SOURCE
1 2011-12-01 A EMAIL
4 2011-12-04 B INTERNET
3 2011-12-03 C MEETING
You need an aggregate and a self join.
This is standard SQL without relying on the MySQL group by extensions (which are rubbish)
Edit, after comment. Assumes one change per day only