Union of two full text queries without duplicates

By Bill Graziano on 23 October 2000 | 1 Comment | Tags: SELECT

David writes "Hi SQL Guru, I am trying to union two queries into one result set using union. Both queries are full text searches using ContainsTable on different tables in the same database. There is one full text catalog shared by both tables. My problem is that I am getting rows that are duplicates in all columns except FullTextTable.Rank . . .

The question continues "I read your artical http://www.sqlteam.com/item.asp?ItemID=289 but using distinct won't work because the duplicate rows are introduced by the union (I tried it out anyway, didn't work with a union).

I also checked out http://www.sqlteam.com/item.asp?ItemID=239 however this won't work either because the FullTextTable.Rank prevents exact duplicates.

Is there a way to not get duplicate rows from unioning full text queries?

SQL server 7 standard edition w/ sp2
NT4 server w/ sp6


First of all my humble apologies for not finding this question sooner. Unfortunately I'm just way behing but catching up. Second, many, many thanks for looking at previous articles before you posted your question. I'm probably a little late in answering but I'm just so excited that someone tried to look up the answer before posting a question that I'm going to give it a shot anyway.

How about using a temp table? Put all your Primary Keys and Ranks into a temp table. Then run a Group by query.

CREATE TABLE #QueryResult (ID int, Rank int)

INSERT #QueryResult
SELECT YourPrimaryKey, FullTextTable.Rank
FROM . . . (and the rest of your query)

INSERT #QueryResult
SELECT YourPrimaryKey, FullTextTable.Rank
FROM . . . (and the rest of your SECOND query)

Select ID, Max(Rank) as Rank
From #QueryResults
Group by ID

This should get each entry once with the highest rank returned? Hope this helps.

Discuss this article: 1 Comment so far. Print this Article.

If you like this article you can sign up for our weekly newsletter. There's an opt-out link at the bottom of each newsletter so it's easy to unsubscribe at any time.

Email Address:

Related Articles

Joining to the Next Sequential Row (2 April 2008)

Writing Outer Joins in T-SQL (11 February 2008)

How to Use GROUP BY with Distinct Aggregates and Derived tables (31 July 2007)

How to Use GROUP BY in SQL Server (30 July 2007)

SQL Server 2005: Using OVER() with Aggregate Functions (21 May 2007)

Server Side Paging using SQL Server 2005 (4 January 2007)

Using XQuery, New Large DataTypes, and More (9 May 2006)

Counting Parents and Children with Count Distinct (10 January 2006)

Other Recent Forum Posts

Shrink DB File by Increment to Target Free Space (6 Replies)

Getting current quarter & 4 previous quarters data (0 Replies)

eat scrumptious caffeine using these guidelines (0 Replies)

eat scrumptious caffeine using these guidelines (0 Replies)

eat scrumptious caffeine using these guidelines (0 Replies)

?????? ??????????? ?????? 2017 (0 Replies)

WITH EXECUTE_AS not working for sproc. (9 Replies)

Data loss during sql cluster failover (3 Replies)

Subscribe to SQLTeam.com

Weekly SQL Server newsletter with articles, forum posts, and blog posts via email. Subscribers receive our white paper with performance tips for developers.

SQLTeam.com Articles via RSS

SQLTeam.com Weblog via RSS

- Advertisement -