SQL - suppressing duplicate *adjacent* records
- by Trevel
I need to run a Select statement (DB2 SQL) that does not pull adjacent row duplicates based on a certain field. In specific, I am trying to find out when data changes, which is made difficult because it might change back to its original value.
That is to say, I have a table that vaguely resembles:
A, 5, Jan
A, 12, Feb
A, 12, Mar
A, 12, Apr
A, 9, May
A, 9, Jun
A, 5, Jul
And I want to get the results:
A, 5, Jan
A, 12, Feb
A, 9, May
A, 5, Jul
discarding adjacent duplicates but keeping the last row. The obvious:
Select Letter, Number, Min(Month) from Table group by Letter, Number
does not work -- it doesn't include the last row.