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
 ORDER BY, most number of keywords.

Author  Topic 

benildusmuerling
Yak Posting Veteran

81 Posts

Posted - 2012-08-23 : 03:22:11
Good day to my excellient members, I would like to ask a question on how would I use the contains keyword.

My scenario, I've got at the moment is to order the records by the most number of keywords.

for example, if someone hit 'Time Travellers Wife' in the search bar, and the table in that column which is searching for, if it is having records as

1) Time
2) Time Travellers
3) Time Travellers Wife

it should return in the order of below.

1) Time Travellers Wife
2) Time Travellers
3) Time

PS : order in the most number of keywords, and then one after the other
Thanks,

AB

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2012-08-23 : 05:40:22
split the words up into a table variable or cte then

select t.title
from tbl t
join @keyword k
on ' ' + t.title + ' ' like '% ' + k.keyword + ' %'
group by t.title
order by count(*) desc

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -