UNION

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
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.
 
Back
Top