sql server 2008 - MS SQL Insert from multiple rows -
i´m trying insert values database several tables:
insert dbo.table1 (id, idtable2, idcounter) select s.id o.idtable2 o.idcounter dbo.table3 o, dbo.table2 s
but above code leads situation duplicate values values table 3, want 1 value table3 per value table 2. (the tables don´t have relationship info)
thanks in advance.
edit:
thanks everyone. managed solve adding reference id table2 , using inner join.
you forgot clause joining tables table2 , table3, building cartesian product. there must linking tables; otherwise makes no sense combine them do.
my advice: stay away old join syntax list tables comma-separated. use up-to-date join syntax (inner join on etc.) instead.
having said this, don't see how select make sense anyhow. id become id of table2 , idtable2 become id of table2, too?
Comments
Post a Comment