0
|ID | Revision |  Title |
-------------------------
| 1 |     1    |  Foo1  |
| 2 |     2    |  Foo2  |
| 3 |     3    |  Foo3  |
| 4 |     2    |  Foo4  |
| 5 |     1    |  Foo5  |
| 6 |     1    |  Foo6  |

So heres the dilemma, try as i might im stuck with this one, i am trying to return the greatest id row data for each revision ( e.g. return row ID 6 for revision 1, 4 for revision 2, 3 for revision 3 ), anyone kind enough to able to help with this one? I was able to return the correct ID using MAX() but the rest of the row data wasn't correct ( e.g. Title was incorrect ).

This doesn't work,

SELECT max(id) as id, title FROM blog GROUP BY revision ORDER BY id ASC

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
Monk
  • 3
  • 1

1 Answers1

1

You could use a subquery to select only the ID's that are the max for a particular Revision:

select * from tbl a
where ID = (
    select max(ID) from tbl b where a.Revision = b.Revision
)
jspcal
  • 50,847
  • 7
  • 72
  • 76