Solved

SQL...Joining VIEWS

Posted on 2013-01-23
4
366 Views
Last Modified: 2013-01-23
I have multiple views, that I need to join together.
I am having a difficult time getting the data to appear like I want.


VIEW 1:

SELECT ORG_ID, ORGANIZATION_NAME, [GROUP], category_id, rpt_list_text, APRN, PA
  FROM vw_core_privileges_a16

ORG_ID	ORGANIZATION_NAME	GROUP	category_id	rpt_list_text	APRN	PA
1	       Northwestern Memorial Hospital	UHC	1	Write admission orders	1	1
2	       Rush University Medical Center	UHC	1	Write admission orders	1	1
3	       University of Chicago	                UHC	1	Write admission orders	1	1

Open in new window



VIEW 2:

SELECT ORG_ID, ORGANIZATION_NAME, [GROUP], category_id, rpt_list_text, APRN, PA
  FROM vw_core_privileges_a17

ORG_ID	ORGANIZATION_NAME	    GROUP	     category_id	rpt_list_text	APRN	PA
1	       Northwestern Memorial Hospital	UHC	    1	  Write discharge orders	   1	1
2	       Rush University Medical Center	UHC	    1	  Write discharge orders	   1	1
3	       University of Chicago	               UHC	    1 	  Write discharge orders	   1	1

Open in new window




I would like the data to appear like:

ORG_ID	ORGANIZATION_NAME	GROUP	category_id	rpt_list_text	APRN	PA
1	       Northwestern Memorial Hospital	UHC	    1	  Write admission orders	   1	  1
2	       Rush University Medical Center	UHC	    1	  Write admission orders	   1	  1
3	       University of Chicago	                UHC	    1	  Write admission orders	   1	  1
1	       Northwestern Memorial Hospital	UHC	    1	  Write discharge orders	   1	  1
2	       Rush University Medical Center	UHC	    1	  Write discharge orders	   1	  1
3	       University of Chicago	               UHC	    1 	  Write discharge orders	   1	  1

Open in new window

0
Comment
Question by:swaggrK
[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
  • 2
4 Comments
 
LVL 12

Accepted Solution

by:
Saurabh Bhadauria earned 250 total points
ID: 38810949
You need a union here ...

SELECT ORG_ID, ORGANIZATION_NAME, [GROUP], category_id, rpt_list_text, APRN, PA
  FROM vw_core_privileges_a16

union all

SELECT ORG_ID, ORGANIZATION_NAME, [GROUP], category_id, rpt_list_text, APRN, PA
  FROM vw_core_privileges_a17
0
 

Author Comment

by:swaggrK
ID: 38811021
Thank you, where is the best place to store this query, since it is not really a View?
0
 

Author Closing Comment

by:swaggrK
ID: 38811037
Excellent!!! Responded very quickly. Thank you.
0
 
LVL 12

Expert Comment

by:Saurabh Bhadauria
ID: 38811047
ok then you can wrap your queries in a view...in  similar way
0

Featured Post

Free eBook: Backup on AWS

Everything you need to know about backup and disaster recovery with AWS, for FREE!

Question has a verified solution.

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

Suggested Solutions

How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
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…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

733 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