Union of two full text queries without duplicates

By Bill Graziano on 23 October 2000 | 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.

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

Need Help in SQL query optimization (2d)

Info needed on field "user_scans" of table "sys.dm_db_index_usage_stats" (3d)

Suspect Parameter Sniffing? (3d)

See values of a proc when it is called from another proc? (4d)

Varchar() datatype and C# SqlDataReader truncates string (4d)

Find the extra rows (5d)

How to represent birth and death record in mysql db without duplicating data of an existing persons table existing persons table (5d)

EPR updates issues (6d)

- Advertisement -