SELECT c."categoryId", c."name", count(DISTINCT ec."entryId") as entryCount FROM "Category" c LEFT JOIN "EntryCategory" ec ON c."categoryId" = ec."categoryId" GROUP BY c."categoryId", c."name" ORDER BY c."name"