In a project I am working on I have the table you can see below. On the frontend I need to show only the records that are published grouped by the entity_id. For example, in the example below only id 1, 11, 16 and 19 should be shown. I have no idea how to make this query. I tried several things with subqueries etc but none of them work. I guess there should be a way to retrieve this data. What am I missing?
| id | revision | entity_id | status
========================================
| 1 | 1 | 1 | published
| 2 | 2 | 1 | archived
| 3 | 1 | 2 | draft
| 4 | 2 | 2 | draft
| 5 | 3 | 2 | draft
| 6 | 4 | 2 | ready
| 7 | 5 | 2 | draft
| 8 | 6 | 2 | published
| 9 | 7 | 2 | published
| 10 | 8 | 2 | ready
| 11 | 9 | 2 | published
| 13 | 1 | 3 | draft
| 14 | 1 | 4 | draft
| 15 | 2 | 4 | draft
| 16 | 3 | 4 | published
| 18 | 1 | 5 | draft
| 19 | 2 | 5 | published
| 20 | 3 | 5 | draft
| 21 | 10 | 5 | archived
I created a DBFiddle to play around: https://www.db-fiddle.com/f/4UcjKhTvzzNQWL3Pfkfew4/1
Note It's not the same as SQL select only rows with max value on a column since the answer there would select all the revisions that are published and not just the latest one.