-- Show all posts that still have tags, along with their tag contents SELECT id, title, tags, (SELECT array_agg(c.name) FROM post_categories pc JOIN categories c ON c.id = pc.category_id WHERE pc.post_id = posts.id) as categories FROM posts WHERE tags IS NOT NULL AND array_length(tags, 1) > 0 ORDER BY title;