Quote:
|
Originally Posted by nzwy1p
select iId, vchName, MAX(iVersion) as iVersion
from <Table>
GROUP BY iId
|
you may think this works, but it doesn't
even the mysql docs tell you that this gives
unpredictable results (holler if you need the link to the page in the docs where it explains this)
what you want is the vchName that comes from the row which has the largest iVersion, but this is not what you are getting, and if it looks like you are getting it, it is a fluke
you could just as easily get this instead --
1|3|Fred edited once
2|3|Dave
i'm sorry if this sounds like i'm dumping all over you, it's not your fault, it's mysql's fault for allowing non-standard sql to run (in any other database system, your query would generate a syntax error)
here's what you want, done without subqueries if you're not on 4.1 yet --
Code:
select X.iId
, X.iVersion
, X.vchName
from yourtable as X
inner
join yourtable as Y
on X.iId
= Y.iId
group
by X.iId
, X.iVersion
, X.vchName
having X.iVersion
= max(Y.iVersion)