开发者

Get the all of the entries from a mysql table where there version is the highest for there ID

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开发者_StackOverflow中文版 to write this query in MySQL it would be very helpful!


For this situation, use:

  SELECT t.refid,
         MAX(t.version) AS max_version
    FROM YOUR_TABLE t
GROUP BY t.refid
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜