table - MySQL INSERT after JOIN -


i have 2 tables shown below.

table1  site | link type -----+----------    | pdf  b   | html  c   | null  d   | null  table2  site | link type -----+----------  c   | htm  d   | doc 

this result want:

site | link type -----+----------    | pdf  b   | html  c   | htm  d   | doc 

i want insert query insert values of link type table 2 table 1
link type null joined condition of table1.site = table2.site.

i tried:

insert table1(linktype) select linktype table1 t1  join table2 t2  on t1.site=t2.site 

i want insert query. update query working , want know how insert can done?

edit: edited after clarification:

creation of table1:

set foreign_key_checks=0; drop table if exists `table1`; create table `table1` (   `site` varchar(250) default null,   `linktype` varchar(250) default null ) engine=innodb default charset=latin1;   insert `table1` values ('a', 'pdf'); insert `table1` values ('b', 'html'); insert `table1` values ('c', null); insert `table1` values ('d', null); 

creation of table2:

set foreign_key_checks=0; drop table if exists `table2`; create table `table2` (   `site` varchar(250) default null,   `linktype` varchar(250) default null ) engine=innodb default charset=latin1;  insert `table2` values ('c', 'htm'); insert `table2` values ('d', 'doc'); 

insert query:

insert      table1       (site, linktype)     (        select             table2.site,             table2.linktype                    table2        join             table1        on             table1.site = table2.site    ) ; 

table1 after insert query:

table1


Comments