Solved

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

Posted on 2013-06-04
2
304 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
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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Server Deadlocks 12 50
What is format f12.8 for a CSV file 6 41
TSQL previous 5 25
Error running stored procedure 11 18
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
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…
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
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

896 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

14 Experts available now in Live!

Get 1:1 Help Now