Solved

*** SQL Combine 2 Queries and Display Rows as Columns

Posted on 2013-06-04
2
303 Views
Last Modified: 2013-06-04
Hello Experts,

I have 2 queries.

1st Query produces:

ID    Status           Qty_BLUE
10    Pending         12
11    Processed      25
12    Completed     14

2nd Query Produces:

ID    Status           Qty_RED
20    Pending          45
21    Processed       31
22    Completed     17

I would like to combine the results from both queries to look like this:

Status           Qty_BLUE    Qty_RED
Pending         12                  45
Processed      25                  31
Completed     14                 17

Your help is GREATLY appreciated!  Thank you!!
0
Comment
Question by:giggul
2 Comments
 
LVL 34

Accepted Solution

by:
Brian Crowe earned 500 total points
Comment Utility
just join the 2 queries on status

SELECT Red.Status, Red.QtyRed, Blue.QtyBlue
FROM
   (SELECT ...) AS Red
INNER JOIN
   (SELECT ...) AS Blue
ON Red.Status = Blue.Status
0
 

Author Comment

by:giggul
Comment Utility
wow, that was easy.  THANKS !!!!!!!
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

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
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.

763 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

9 Experts available now in Live!

Get 1:1 Help Now