Anish
Anish

Reputation: 912

Searching query to get records without duplicate

I would like to write a SQL query in a SQL Server stored procedure so that the result will not have duplicate rows. I have a table containing the following fields

ArticleId, Topic, Introduction, ArticleText, TagsAndKeywords 

(TagsAndKeywords are some info to make search easier)

Suppose the user is giving a search for "Best practices in SQL".

Then the query should do

  1. a full text match in Topic first, Introduction, TagsAndKeywords & ArticleText
  2. split the search text (here 4 words) and search it inside Topic, Introduction, TagsAndkeywords and ArticleText

I want to get a single table without duplicate rows. Please assist me to solve this

Thanks

Upvotes: 0

Views: 212

Answers (2)

Shailesh
Shailesh

Reputation: 1218

User below mentioned query. Seems ArticleId is PK show including PK in the Select will again produce duplicate results.

Select Distinct Topic, Introduction, ArticleText, TagsAndKeywords From myTable Where ...

Cheers.

Upvotes: 0

Jānis
Jānis

Reputation: 2266

Use "Distinct" keyword

Select Distinct ArticleId, Topic, Introduction, ArticleText, TagsAndKeywords 
From myTable
Where ...

Upvotes: 3

Related Questions