?
Solved

Creating mirror results in SELECT statement

Posted on 2014-02-10
2
Medium Priority
?
318 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 16

Accepted Solution

by:
Surendra Nath earned 2000 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

Quick Cloud Training

Looking for some quick training on the cloud in 2 hours or less? Check out these how-to guides in AWS, Linux, OpenStack, Azure, and more!

Question has a verified solution.

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

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…
Suggested Courses

752 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