You've added an additional column to your grouping, so if you have 5 unique quotes for any keyword, of course the count for each combination will be 1. Try:
select k.Keyword, k.QuoteId,
count(*) OVER (PARTITION BY k.Keyword) AS TotalTags
from [enter_your_database_name_here].[dbo].Keywords AS k
INNER JOIN [enter_your_database_name_here].[dbo].QuoteImages AS q
ON k.QuoteId = q.QuoteId
group by k.Keyword, k.QuoteId;
If you don't want to see a row for each QuoteId
, then take it out of both the SELECT
list and the GROUP BY
. You might also not care about the join at all, why not gamble to maybe get slightly better performance (or, at worst, the same):
SELECT k.Keyword, COUNT(*) AS TotalTags
FROM [enter_your_database_name_here_if_you_want_to
run_from_another_database_for_some_reason].dbo.Keywords AS k
WHERE EXISTS
(
SELECT 1 FROM [enter_your_database_name_here_if_you_want_to
run_from_another_database_for_some_reason].dbo.QuoteImages
WHERE QuoteID = k.QuoteID
)
GROUP BY k.Keyword;
If you don't care about the individual Quotes then I have no idea why you added . You say you got an error, but is this because you added it only to the SELECT list or only to the GROUP BY list? Why would you introduce it to either list?