PDA

View Full Version : on duplicate key update


BubikolRamios
02-17-2010, 11:13 AM
insert into target_table (
select t.id_tezaver as child_id,t1.id_tezaver as parent_id from tezaver t
join tezaver t1 on t1.term= 'geraniaceae' and t1.l2 = 'la'
where t.term = 'Geranium pratense'
)
on duplicate key update parent_id = parent_id;


Does not work, no error doh, looks like it updates but new walue is 0 instead expected one.

Inner select is OK, that is, returns like 1003 and 3456.
1003 i.e child_id, which is key, exists in target_table.


How to make it work ?

BubikolRamios
02-17-2010, 11:24 AM
This works. Use of actual field instead of alias.

insert into target_table (
select t.id_tezaver as child_id,t1.id_tezaver as parent_id from tezaver t
join tezaver t1 on t1.term= 'geraniaceae' and t1.l2 = 'la'
where t.term = 'Geranium pratense'
)
on duplicate key update parent_id = t1.id_tezaver ;