?
Solved

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

Posted on 2013-06-04
2
Medium Priority
?
316 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
[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 34

Accepted Solution

by:
Brian Crowe earned 2000 total points
ID: 39219712
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
ID: 39219814
wow, that was easy.  THANKS !!!!!!!
0

Featured Post

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

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

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Suggested Courses

762 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