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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 using insert with inner join

Author  Topic 

mirza21
Starting Member

11 Posts

Posted - 2009-05-22 : 03:55:41
Can we use insert statement with innner join to get refrence to any of the base tables so that we can insert in one of these table


plz help with an example

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-05-22 : 03:57:42
yes you can

insert into sometable ( <somecol> )
select t1.acol, t1.othcol, t2.anothercol
from atable t1
inner join anothertable t2 on t1.pk = t2.pk
where <some condition>


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-05-22 : 04:10:25
[code]
insert into table1 (columns...)
select t2.columns..
from table2 t2
left join table1 t1
on t1.pk=t2.fk
where t1.pk is null
[/code]
Go to Top of Page
   

- Advertisement -