This is my table structure:
// posts
+----+-----------------------------+-----------+------------+
| id | body | edited_id | date_time |
+----+-----------------------------+-----------+------------+
| 1 | post1 | NULL | 1464136759 |
| 2 | post2 | NULL | 1464136760 |
| 3 | post2 edited | 2 | 1464136761 |
| 4 | post2 eduted again | 2 | 1464136762 |
+----+-----------------------------+-----------+------------+
As you can see, table above keeps both posts and their edition version. Currently I'm selecting posts like this:
SELECT * FROM posts WHERE id IN (1,2) ORDER BY date_time ASC;
Current output:
| 1 | a question | NULL | 1464136759 |
| 2 | my answer | NULL | 1464136760 |
Expected output:
| 1 | a question | NULL | 1464136759 |
| 4 | my answer eduted again | 2 | 1464136762 |
see? The post id = 2
has two edition versions, and I always need to select be biggest one (according to date_time
). How can I do that?