I have three tables -
podcasts, videos and others.
Each of the entities under these are associated with a category and subcategories.
Example for podcasts -
This category_id and subcategory_id have their name values in their respective tables -
Now, I want to get the count of podcasts, videos and text under each category & subcategory combination. My individual SQL query are these -
For podcasts -
SELECT c.category_name, sc.sub_category_name, count(p.*) AS podcast_count
FROM podcasts p
JOIN categories c ON c.category_id = p.podcast_category_id
JOIN sub_categories sc ON sc.sub_category_id = p.podcast_subcategory_id
WHERE p.podcast_owner = 14 AND p.podcast_upload_time_stamp >= timestamp '2020-10-22 00:00:00'
GROUP BY 1, 2
For others -
SELECT c.category_name, sc.sub_category_name, count(o.*) AS other_count
FROM otherlinks o
JOIN categories c ON c.category_id = o.other_link_category_id
JOIN sub_categories sc ON sc.sub_category_id = o.other_link_subcategory_id
WHERE o.other_link_owner = 14 AND o.other_link_add_time_stamp >= timestamp '2020-10-22 00:00:00'
GROUP BY 1, 2
And similar one for videos
Now, I want to combine them into a single query so that I get three columns for counts in a single result - podcast_count, other_count and videos_count. How do I do that?



xx_countcolumns to each of the three queries (, 0 AS other_count, 0 AS videos_countfor the first one) thenUNIONthem.