Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Join 3 table with one Output

Status
Not open for further replies.

171171

Programmer
May 13, 2003
16
ID
Hi,

I want join 3 table to Store Procedure or View Example :

Table A :
No. Name
001 Fish
003 Mouse
005 Horse

Table B :
001 Fish
002 Dog

Table C :
No Name
002 Dog
004 Cat
006 Monkey

I want Output is :
Table A Table B Table C
001 001 -
- 002 002
003 - -
- - 004
005 - -
- - 006

Can you Help Me ? Please ...


Thank's

 

select
(case when A.id is not null then A.id else '-' end) as [Table A],
(case when B.id is not null then B.id else '-' end) as [Table B],
(case when c.id is not null then C.id else '-' end) as [Table C]
from
(select * from A union select * from B union select * from C)D
left join A on A.id = D.id
left join B on B.id = D.id
left join C on C.id = D.id
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top