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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

combining three tables into one

Status
Not open for further replies.

fikir

Programmer
Jun 25, 2007
86
0
0
I have three tables tbl1, tbl2 and tbl3, all having employee info

Code:
 declare @tbl1 table (id int name varchar(20)
 declare @tbl2 table (id int name varchar(20)
 declare @tbl3 table (id int name varchar(20)

insert into @tbl1
select 1, 'John'
union all select 2, 'Merry'
union all select 3, 'Larry'

insert into @tbl1
select 1, 'John'
union all select 2, 'Merry'
union all select 4, 'Barry'

insert into @tbl1
select 4, 'Barry'
union all select 5, 'Bob'
union all select 6, 'Kerry'

I want to bring all unique records across the table and insert them to a fouth table.

therefore my fourth table should look like

tbl4
id name

1 John
2 Merry
3 Larry
4 Barry
5 Bob
6 Kerry


any suggestion?

Thanks,


 
insert into @tbl4
select id,name from @tbl1 union
select id,name from @tbl2 union
select id,name from @tbl3

r937.com | rudy.ca
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top