Reputation: 89
Version:mysql Ver 14.14 Distrib 5.7.25, for Linux
Table articles:
id` int(11) NOT NULL AUTO_INCREMENT,
`title` varchar(120) NOT NULL,
`creator` varchar(45) NOT NULL,
`versionid` varchar(45) NOT NULL,
`content` mediumtext NOT NULL,
`category` varchar(45) NOT NULL,
`publishdate` varchar(120) NOT NULL,
`state` varchar(45) NOT NULL,
PRIMARY KEY (`id`)
When an article is updated he gets a new id, but versionid is the same. I can't find a query to Select all articles, but only the newest of those, which have the same versionid.
Upvotes: 0
Views: 32
Reputation: 31991
use correlated subquery
select t1.* from table_name t1
where t1.id= ( select max(id)
from table_name t2 where t1.versionid=t2.versionid
)
Upvotes: 1