Link to home
Start Free TrialLog in
Avatar of yadavdep
yadavdepFlag for India

asked on

Search Query in SQl server 2012

I have two tables Articles and Article_Keywords
Here is the table structure
Articles
1. ArticleID (PK)
2. Title
3. Details
Article_Keywords
1. ArticleKeywordID (PK)
2. ArticleID
3. Keyword


Articles are to stored users article which has a title and a details field.
Article_Keywords is used to keywords for an article, it can be one or many for a single article.

Now, I need to give search feature to the users where user can search on article Keywords. Also there is a advance search option where they can search on keywords , title and details.


I am not good in writing sql queries
but what I was thinking of writing query for the first option (search only in keywords)
is select * from articles where articleid in (select articleid from Article_Keywords where keywords like %@parameters%)

And for the second part (search in keywords, title and details)
select * from articles where articleid in (select articleid from Article_Keywords where keywords like %@parameters%)
and title like %@parameters% and details like %@parameters%


I need know will these would be the best option to do search in these tables
SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of yadavdep

ASKER

Hi Vitor,

would joins be better in terms of performance ?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial