Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
I have 2 tables with the same structure as following:Table A:ID | Name-----+----- 1 | AA 2 | BBTable B:ID | Name-----+----- 3 | CC 4 | DDI want to join them into one as following:Table A:ID | Name-----+----- 1 | AA 2 | BB 3 | CC 4 | DD
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts
Posted - 2006-11-20 : 04:38:44
Have you tried doing it on your own?
declare @t1 table( [id] int, [name] varchar(20))declare @t2 table( [id] int, [name] varchar(20))insert @t1select 1, 'AA' union allselect 2, 'BB'insert @t2select 3, 'CC' union allselect 4, 'DD'select * from @t1union allselect * from @t2
Harsh AthalyeIndia."Nothing is Impossible"
mchohan
Starting Member
39 Posts
Posted - 2006-11-20 : 05:08:56
select ID,Name from TableAUnion Allselect ID,Name from TableB(Union All to include duplicates)
John12345
Starting Member
3 Posts
Posted - 2006-11-20 : 08:37:20
Thanks guys,I have another question.I have these 2 tables:Table A:ID | Name---+-----1 | AA2 | BBTable B:Age | Gender-----+-------- 10 | Male 20 | FemaleI want to join them into one as following:ID | Name | Age | Gender---+------+-------+--------1 | AA | 10 | Male2 | BB | 20 | FemaleIs it possible ?
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts
Posted - 2006-11-20 : 08:43:00
What is the common column between the two tables?It doesn't make sense unless both tables have something in common.Harsh AthalyeIndia."Nothing is Impossible"
John12345
Starting Member
3 Posts
Posted - 2006-11-20 : 08:57:20
Let's say we have:Table A:ID | Name---+-----1 | AA2 | BBTable B:ID | Gender-----+--------1 | Male2 | FemaleAnd want:ID | Name | Gender---+------+-------1 | AA | Male2 | BB | Female
SwePeso
Patron Saint of Lost Yaks
30421 Posts
Posted - 2006-11-20 : 09:00:28
You better start a new topic, if this new question of yours is different from the original question.This is better from a search point of view and other can benefit from the answers we give you.select t1.id, t1.name, t2.genderfrom tableA t1 inner join tableB t2 on t2.id = t1.idPeter LarssonHelsingborg, Sweden