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