Solved

Creating mirror results in SELECT statement

Posted on 2014-02-10
2
299 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

747 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

11 Experts available now in Live!

Get 1:1 Help Now