Solved

Creating mirror results in SELECT statement

Posted on 2014-02-10
2
304 Views
Last Modified: 2014-02-10
Hi,

I have simple select query that returns results similar to this:

rel_type_id      left_name      right_name
35      Parent      Child
36      Referenced By      Reference To
37      Propagated From      Propagated To

I need to add something clever to the SQL that will automatically create the mirror of these thus returning 6 results, ideally with a new column with zero denoting original and 1 denoting the mirror

rel_type_id      left_name      right_name      Type
35      Parent      Child      0
36      Referenced By      Reference To      0
37      Propagated From      Propagated To      0
35      Child      Parent      1
36      Reference To      Referenced By      1
37      Propagated To      Propagated From      1

Any suggestions greatly appreciated.
0
Comment
Question by:andyw27
2 Comments
 
LVL 16

Accepted Solution

by:
Surendra Nath earned 500 total points
ID: 39847467
you can do it as below

select  *, '0' as Type from <your table> -- This is your original query
union all
select  *, '1' as Type  from <your table> -- This is the mirrored query

Open in new window

0
 

Author Comment

by:andyw27
ID: 39847524
cool, simple when you know how.  Thanks for the quick reply.
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
I have a large data set and a SSIS package. How can I load this file in multi threading?
Viewers will learn how the fundamental information of how to create a table.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

27 Experts available now in Live!

Get 1:1 Help Now