UNION

G

Guest

Hello,
I have a SELECT statement
(SELECT DISTINCT Products FROM Shelf
UNION
SELECT ' @#@#@#@#' AS Col1 FROM Shelf) that returns:

Products
--------
@#@#@#@#
Alcoholic Beverages
Milk

I have another SELECT statement
(SELECT DISTINCT Food FROM Shelf
UNION
SELECT ' @#@#@#@#' AS Col1 FROM Shelf) that returns:

Food
-------
@#@#@#@#
Pasta
Pizza

And I want to retrieve a result of the union of the 2
SELECT statements in the original ordering of the
members, i.e.:

Products
----------
@#@#@#@#
Alcoholic Beverages
Milk
@#@#@#@#
Pasta
Pizza

How can I do it? When I tried to use UNION, the result
was reordered and I the result I got was:

Products
----------
@#@#@#@#
@#@#@#@#
Alcoholic Beverages
Milk
Pasta
Pizza
 
G

Guest

Hi,

Use UNION operation if you don't want to return duplicate records or use the
UNION ALL operation if you do want to return duplicate records.

I did not get the results back as sorted. But, it did remove the extra "
@#@#@#@#". When I use "UNION ALL", then it gives me the right result.
Double check if you have any sort in your query.

Hope this helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Union Query 1
Repetitive Results 3
Trouble summing yes/no checkbox fields in query 9
Union query 5
Union Query 0
UNION question 3
DISTINCT Query Help 2
Union query not displaying select statement 1

Top