Reputation: 53
I'm working on a revision control system for my database entries.
I have 2 values that need to be checked for this, RefID (which is an id for the asset itself) and version which is what version this entry is, the RefID is the same for all versions. What I want to do is get all of the entries that have unique RefIDs while being the highest version ID, basically the HEAD of all the entries.
If anyone knows how to write this query in MySQL it would be very helpful!
Upvotes: 0
Views: 42
Reputation: 332691
For this situation, use:
SELECT t.refid,
MAX(t.version) AS max_version
FROM YOUR_TABLE t
GROUP BY t.refid
Upvotes: 3