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;

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
)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.