jeudi 26 mars 2015

Select from 2 unrelated tables and merge unique ID columns


Vote count:

0




I'm trying to return a combined result of data from 2 tables, but need to merge the ID column from both to form one result set, the full outer join is the closest I have to returning the correct row number. Example: T1

ID A a s b s e s f s


T2

ID B a a c a d a f a


Result

ID A B a s a b s NULL c NULL a d NULL a e s NULL f s a



declare @t1 table (
ID varchar(1),
A varchar(1)
)


insert into @t1 values ('a','s') insert into @t1 values ('b','s') insert into @t1 values ('e','s') insert into @t1 values ('f','s')


declare @t2 table ( ID varchar(1), B varchar(1) )


insert into @t2 values ('a','a') insert into @t2 values ('c','a') insert into @t2 values ('d','a') insert into @t2 values ('f','a')


select * from @t1 select * from @t2



asked 1 min ago







Select from 2 unrelated tables and merge unique ID columns

Aucun commentaire:

Enregistrer un commentaire