我有这个问题:
SELECT page.id, revision.title, revision.number FROM page INNER JOIN revision ON page.id = revision.pageId
哪个会返回如下内容:
"1" "Page Version A" "1" "1" "Page Version B" "2" "1" "Page Version C" "3"
现在我只想为每个页面返回一行,其中包含最新(编号最高)修订版的数据.如果我做:
SELECT page.id, revision.title, revision.number FROM page INNER JOIN revision ON page.id = revision.pageId GROUP BY page.id
我明白了:
"1" "Page Version A" "1"
但我想要:
"1" "Page Version C" "3"
有任何想法吗?谢谢.
添加类似的WHERE子句
WHERE revision.number =(从版本r中选择max(number),其中r.pageId = page.id)