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.
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.keywordFROM IPI_Photographers_KeywordID AS I INNER JOIN IPI_Keywords AS k ON k.KeywordID = I.KeywordIDORDER BY I.KeywordID DESC |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-10-22 : 17:18:28
|
[code]SELECT k.keywordFROM IPI_Photographers_KeywordID AS I INNER JOINIPI_Keywords AS k ON k.KeywordID = I.KeywordIDGROUP BY k.keywordORDER BY COUNT(I.KeywordID) DESC[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
RichardSteele
Posting Yak Master
160 Posts |
Posted - 2012-10-22 : 17:50:33
|
Great, but how can I show the quantity for each? |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2012-10-22 : 18:11:49
|
Just add a count:SELECT k.keyword, COUNT(*) AS KeywordCountFROM IPI_Photographers_KeywordID AS I INNER JOINIPI_Keywords AS k ON k.KeywordID = I.KeywordIDGROUP BY k.keywordORDER BY COUNT(I.KeywordID) DESC |
|
|
RichardSteele
Posting Yak Master
160 Posts |
Posted - 2012-10-22 : 18:20:57
|
Great! Thanks! |
|
|
|
|
|