I have two tables with a one to many relationship, offer and offer_rows
I want to fetch multiple offers with their content rows. That on it’s own is not difficult, I just use an
INNER JOIN on offer.offer_id = offer_rows.offer_id
However, the offer_rows table contains a field called revision and the query needs to always fetch all the rows with the highest revision number. Is this possible with a single query?
I realize I could change the database design, by adding a third table called offer_revision, I could join this table with a select condition to fetch the latest revision number and then connect this table to the rows. This however would take considerable refactoring so I only want to do it if I have to.
I also want to do this with a direct query – no stored procedures.
Of course it is possible: