Solved

SQL...Joining VIEWS

Posted on 2013-01-23
4
362 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
  • 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
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…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.

707 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

13 Experts available now in Live!

Get 1:1 Help Now