Wrox Home  
Search P2P Archive for: Go

  Return to Index  

sql_language thread: Ranking Results Question


Message #1 by joris_de_beer@d... on Tue, 17 Apr 2001 03:35:14
Hi all,

My question:
How can a sort my PageID's by those that have the most number of matching 
KeywordID's.

Explanation of my code:
I'm trying to build a 'Related Articles' Query so that the results can be 
displayed at the bottom of a page on our website. The concept is to look 
at the Keywords that the current page has, then find matching pages with 
the same keywords. Finally, pages which have the most matching keywords 
should be at the top of the list. After that it should sort by date.

A DB structure is like this: tblPage contains the page data, title, and of 
course the pageID. Another table, tblKeywordBridge contains pageID's and 
corresponding keywordID's. The actual keywords and the keywordID are 
stored in another table, tblKeywords, but this isn't searched with this 
query.

I'm thinking I need to use COUNT or GROUP BY

SELECT dbo.tblKeywordBridge.pageID, title  
FROM dbo.tblKeywordBridge, dbo.tblPage  
WHERE dbo.tblKeywordBridge.pageId = dbo.tblPage.pageId  
AND keywordID IN  
	(SELECT KeywordID  
	 FROM tblKeywordBridge  
	 WHERE pageId = '1429') 
ORDER BY dbo.tblKeywordBridge.pageId DESC


I just joined up today, so please forgive me if this has already been 
covered. Unfortunately it has had me stumped for all of Easter.

Thanks in advance

  Return to Index