tsql - Most Efficient way to insert multiple rows of integers -


i have 2 simple select queries me list of id's. first table returns lets 5 ids. 1, 2, 5, 10, 23

my second table returns list of 50 ids not in order.

whats efficient way write query map each of ids first table ids second table?

edit: sorry here more info.

if table 1 has result of ids = 1, 2, 5, 10, 23 , table 2 has list of ids = 123, 234, 345, 456, 567

i write insert insert table 3 these values

 table1id | table2id          1|123           1|234          1|345          1|456          1|567          2|123           2|234          2|345          2|456          2|567 

and on.

it seems looking cartesian product.

you can accomplish joining 2 tables no join condition, accomplished cross join.

insert dbo.tablec (aid, bid) select a.id, b.id    dbo.tablea    cross join dbo.tableb b ; 

here image visualization of cartesian product. inputs small, column of symbols on left corresponding first table, , column on right being second table. upon performing join no conditions, 1 row per connecting line in middle.

cartesian product


Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

java Extracting Zip file -

C# WinForm - loading screen -