I have two tables: Phrase and PhraseCategory
They are linked with Phrase.CategoryId == PhraseCategory.PhraseCategoryShortId
CREATE TABLE [dbo].[Phrase] ( [PhraseId] UNIQUEIDENTIFIER DEFAULT (newid()) NOT NULL, [English] NVARCHAR (250) NOT NULL, [CategoryId] INT NULL, PRIMARY KEY CLUSTERED ([PhraseId] ASC) ); CREATE TABLE [dbo].[PhraseCategory] ( [PhraseCategoryShortId] INT IDENTITY (1, 1) NOT NULL , [Name] VARCHAR (100) NOT NULL, PRIMARY KEY CLUSTERED ([PhraseCategoryShortId] ASC) ); Can someone help give me some advice on how I can join these so that I get a report looking like this:
PhraseCategory.Name Qty Here's what I have so far:
SELECT PhraseCategory.name, count(*) AS qty FROM Phrase LEFT OUTER JOIN PhraseCategory ON Phrase.CategoryId = PhraseCategory.PhraseCategoryShortId GROUP BY PhraseCategory.name ORDER BY PhraseCategory.name The problem for me is that I want it to show the Phrase Category name and a 0 if there are no rows with that category. So far I cannot get this to work.