Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Creating mirror results in SELECT statement

Posted on 2014-02-10
2
Medium Priority
?
323 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

618 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