当我的数据库中有一个没有帖子的类别时,结果选择返回没有空类别的行。如何接收具有空类别的表格。
SELECT
c.id as category_id,
pp.id as post_id
FROM categories c,
LATERAL
(SELECT
id
FROM posts
WHERE c.id = posts.category_id
ORDER BY views DESC
LIMIT 2) pp
ORDER BY c.category ASC, pp.id ASC
当前查询结果:
category_id | post_id
----------------------
1 | 1
1 | 2
3 | 3
3 | 4
我需要:
category_id | post_id
----------------------
1 | 1
1 | 2
2 |
3 | 3
3 | 4