I have a simple table comments (id int, revision int, comment varchar(140))
with some content like this:
1|1|hallo1|
1|2|hallo2|
1|3|hallo3|
2|1|hallo1|
2|2|hallo2|
I'm searching for a sql statement which will return each comment with the highest revision:
1|3|hallo3|
2|2|hallo2|
I've got a solution
select id, revision, comment
from comments
where revision = (
select max(revision)
from comments as f
where f.id = comments.id
);
but it is very slow on large data sets. Any better solution?