When I have in my DB a category without posts, the resulted select returns rows without an empty category. How to do receiving a table with empty category.
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
Current query result:
category_id | post_id
----------------------
1 | 1
1 | 2
3 | 3
3 | 4
I need:
category_id | post_id
----------------------
1 | 1
1 | 2
2 |
3 | 3
3 | 4