我有两个表,它们是:
posts (which contains the core post data):
id
type
is_published
visibility
enable_comments
views
和
post_versions (which contains the posts version such as drafts and final version):
id
post (foreign key posts.id)
format
title
slug
description
thumbnail
content
created_by
我想做的是通过检索每个帖子的最新版本来获取所有帖子。我知道如何获取所有帖子的所有版本,例如:
SELECT p.id, p.is_published, p.visibility, p.enable_comments, p.views,
pv.format, pv.title, pv.slug, pv.description, pv.thumbnail,
pv.content, pv.created_by
FROM posts p
INNER JOIN post_versions pv on (p.id = pv.post)
WHERE p.type = 1
但是我不知道如何对每条posts
记录联接和获得一行post_versions
中的最新记录。