好的,所以假设我有以下表格:
食谱
id (pk)
name
added
modified
食谱版本
id (pk)
recipe_id (fk to recipes.id)
version
content
added
我想要的是一个获取最新recipe_versions.added
数据然后与基础recipe
数据连接的查询。然后对所有结果进行排序,recipes.added ASC
我有以下内容,但是 group by 没有选择最新的 recipe_versions 行,似乎选择了第一个。
SELECT r.`id`,
r.name,
rv.version,
rv.content,
r.added,
r.modified,
FROM recipes r,
recipe_versions rv
WHERE r.`id` = rv.recipe
GROUP BY rv.recipe
HAVING max(rv.added)
ORDER BY r.added ASC