0

I need some help writing a sql query. I have below 2 queries and I want to combine them together.

Now I already tried union but it doesn't work. I first want to print all result of query1 than I want to print all results for query2.

Ex:

--Query#1 results:

|----|------|
| id | obj  |
|----|------|
| 1  | car  |
| 2  | tree |
|----|------|

--Query#1 results:

|----|------|
| id | obj  |
|----|------|
| 1  | bob  |
|----|------|

Than I want to comibine by printing all result for query1 than print all result for query2 like this below:

--combine result:

|----|------|
| id | obj  |
|----|------|
| 1  | car  |
| 2  | tree |
| 1  | bob  |
|----|------|

--Query#1

SELECT DISTINCT a.[rank], b.Description
    FROM CONTAINSTABLE(myTable, *, '"ra*'") AS a
        INNER JOIN myTable AS b ON a[key] = b.ID
             ORDER BY a.rank desc;

--Query#2

SELECT DISTINCT a.[rank], b.Description
    FROM FREETEXTTABLE(myTable, *, '"ra'") AS a
        INNER JOIN myTable AS b ON a[key] = b.ID
             ORDER BY a.rank desc;

Edited by hwoarang69

2
Contributors
1
Reply
18
Views
1 Year
Discussion Span
Last Post by rch1231
0

Hello,

I am guessing that you left the semicolons in place when you ran the union....

This should work:

(SELECT DISTINCT a.[rank], b.Description
    FROM CONTAINSTABLE(myTable, *, '"ra*'") AS a
        INNER JOIN myTable AS b ON a[key] = b.ID
             ORDER BY a.rank desc
)
UNION
(SELECT DISTINCT a.[rank], b.Description
    FROM FREETEXTTABLE(myTable, *, '"ra'") AS a
        INNER JOIN myTable AS b ON a[key] = b.ID
             ORDER BY a.rank desc
)
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.