Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Showing Most Popular Keywords

Author  Topic 

RichardSteele
Posting Yak Master

160 Posts

Posted - 2012-10-22 : 16:47:26
I would like to count the popularity of our keywords with each keyword having a unique keywordID.

The following table pulls the data and puts each id together, but I can't figure out how to count the total number of each keyword and order them with the most popular (largest count) on top. Any help would be greatly appreciated. Thanks!

SELECT I.KeywordID, k.keyword
FROM IPI_Photographers_KeywordID AS I INNER JOIN
IPI_Keywords AS k ON k.KeywordID = I.KeywordID
ORDER BY I.KeywordID DESC

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-10-22 : 17:18:28
[code]
SELECT k.keyword
FROM IPI_Photographers_KeywordID AS I INNER JOIN
IPI_Keywords AS k ON k.KeywordID = I.KeywordID
GROUP BY k.keyword
ORDER BY COUNT(I.KeywordID) DESC
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

RichardSteele
Posting Yak Master

160 Posts

Posted - 2012-10-22 : 17:50:33
Great, but how can I show the quantity for each?
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2012-10-22 : 18:11:49
Just add a count:
SELECT  k.keyword, COUNT(*) AS KeywordCount
FROM IPI_Photographers_KeywordID AS I INNER JOIN
IPI_Keywords AS k ON k.KeywordID = I.KeywordID
GROUP BY k.keyword
ORDER BY COUNT(I.KeywordID) DESC
Go to Top of Page

RichardSteele
Posting Yak Master

160 Posts

Posted - 2012-10-22 : 18:20:57
Great! Thanks!
Go to Top of Page
   

- Advertisement -