SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Showing Most Popular Keywords
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

RichardSteele
Posting Yak Master

158 Posts

Posted - 10/22/2012 :  16:47:26  Show Profile  Reply with Quote
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

India
52249 Posts

Posted - 10/22/2012 :  17:18:28  Show Profile  Reply with Quote

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


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

Go to Top of Page

RichardSteele
Posting Yak Master

158 Posts

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

Lamprey
Flowing Fount of Yak Knowledge

4352 Posts

Posted - 10/22/2012 :  18:11:49  Show Profile  Reply with Quote
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

158 Posts

Posted - 10/22/2012 :  18:20:57  Show Profile  Reply with Quote
Great! Thanks!
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.2 seconds. Powered By: Snitz Forums 2000