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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 query join

Author  Topic 

cipriani1984
Constraint Violating Yak Guru

304 Posts

Posted - 2009-05-11 : 12:01:46
Hi,

I have 2 tables:

Table a:
dept_code
21
22
23
24
25

table b:
dept_code
21
22
23
26
27
28

I joined the 2 tables up with full outer join, to bring everything back but its not?

select a.dept_code
from a full outer join b on a.dept_code = b.dept_code

Is there a way to merge the dept_code field from both tables instead of:

a.dept_code, b.dept_code
21, 21
22, 22
23, 23
24, NULL
NULL, 26
etc

Thanks

robvolk
Most Valuable Yak

15732 Posts

Posted - 2009-05-11 : 12:03:21
How about using INNER JOIN?
Go to Top of Page

cipriani1984
Constraint Violating Yak Guru

304 Posts

Posted - 2009-05-11 : 12:05:06
quote:
Originally posted by robvolk

How about using INNER JOIN?



No, I would the outcome field to list them all,

table a:
dept_code
21
22
23
24
25

table b:
dept_code
21
22
23
26
27
28

outcomes:

dept_code
21
22
23
24
25
26
27
28
Go to Top of Page

kira
Starting Member

17 Posts

Posted - 2009-05-11 : 12:09:03
how about using UNION?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-05-11 : 12:09:42
[code]
SELECT dept_code
FROM
(
SELECT dept_code FROM tablea
UNION
SELECT dept_code FROM tableb
)t
ORDER BY dept_code
[/code]
Go to Top of Page
   

- Advertisement -