Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Joining two queries from 2 tables horizontally

Author  Topic 

Laylow
Starting Member

14 Posts

Posted - 2011-02-23 : 06:13:15
Please help.
How can I join results from two tables to stack up together?

Query 1
SELECT CODE, SUM (AMOUNT * -1), JRNAL
FROM TABLE A
WHERE CODE LIKE 'MXER__' AND JRNAL = 'APU'
GROUP BY JRNAL, CODE
ORDER BY CODE

Query 2

SELECT ACCNT_CODE, SUM (AMOUNT * -1), JRNAL
FROM TABLE B
WHERE CODE LIKE 'MXER__' AND JRNAL = 'APX'
GROUP BY JRNAL, CODE
ORDER BY CODE

How can I have my result to come out (stacked together) in the format below as opposed to having 6 columns. All the normail joins I did gave me 6 colums which is not ideal

CODE__ AMOUNT___ JRNAL
MXER01 100______ APU
MXER01 50_______ APX
MXER02 200______ APU
MXER02 300______ APX

Kind Regards

Laylow

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-02-23 : 06:21:11
[code]
SELECT CODE, SUM (AMOUNT * -1), JRNAL
FROM TABLE A
WHERE CODE LIKE 'MXER__' AND JRNAL = 'APU'
GROUP BY JRNAL, CODE
ORDER BY CODE

union all

SELECT ACCNT_CODE, SUM (AMOUNT * -1), JRNAL
FROM TABLE B
WHERE CODE LIKE 'MXER__' AND JRNAL = 'APX'
GROUP BY JRNAL, CODE
ORDER BY CODE
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

Laylow
Starting Member

14 Posts

Posted - 2011-02-23 : 06:35:44
Thnaks khtan.

That did it!

Regards

Laylow
Go to Top of Page
   

- Advertisement -