I have my data split across two tables. One is the entity table where it describes the basics of the entity, and the revision table where the data of an entity resides. If I know the entity I can query for the most recent version:
SELECT *
FROM `entities`
JOIN (SELECT *
FROM `revisions`
WHERE `entity_fk` = ?
ORDER BY `revised` DESC
LIMIT 0, 1) as `revision`
ON `entities`.`id` = `revision`.`entity_fk`
But now I need to list all entities using data from their most recent revision.
revisions table
+--+---------+---------+--------------------+-------------------+
|id|entity_fk|title |body |revised |
+==+=========+=========+====================+===================+
|01| 01 |Hentity A|This Is tH3 first...|2010-08-30 10:02:45|
|02| 01 |Entity A |This is the first...|2010-08-30 10:16:30|
|03| 02 |Entity B |This is another... |2010-08-30 10:20:20|
What the query should return is a list of the most recent revisions for each entity, not just a specified entity.
2,1,Entity A,This is the first...,2010-08-30 10:16:30
3,2,Entity B,This is another...,2010-08-30 10:20:20