How can I get the rows with the distinct TypeID with the maximum EffectivityDate?
Original Table
-----------------------------------------
| ID | TypeID | Value | EffectivityDate |
-----------------------------------------
| 1 | 1 | 2.3 | 1990-01-01 |
| 2 | 1 | 3.4 | 1999-10-31 |
| 3 | 2 | 1.1 | 1990-01-01 |
| 4 | 2 | 2.2 | 1999-10-31 |
| 5 | 3 | 6.1 | 1999-10-31 |
-----------------------------------------
Query Result
-----------------------------------------
| ID | TypeID | Value | EffectivityDate |
-----------------------------------------
| 2 | 1 | 3.4 | 1999-10-31 |
| 4 | 2 | 2.2 | 1999-10-31 |
| 5 | 3 | 6.1 | 1999-10-31 |
-----------------------------------------
Any help?
You can get their maximum
EffectiveDatein a subquery then join it again with its own table,SQLFiddle Demo