CodeIgniter Forums
SQL delete on duplicate problem - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: SQL delete on duplicate problem (/thread-20575.html)



SQL delete on duplicate problem - El Forum - 07-14-2009

[eluser]sszynrae[/eluser]
hi, im having some problems with a query meant to do parts of the work of merging together two elements my n-m relational table tagmap

tagmap:
eid (links to the id in my entry table)
tid (links to the id in my tag table)

primary = (eid,tid)

I'm trying to do:
->query('UPDATE tagmap SET tid='.$oldid.' WHERE tid='.$newid.
' ON DUPLICATE DELETE tagmap WHERE tid='.$oldid.' AND eid=VALUES(eid)');

so merging together two tags should here change the tid of all tagmaps from $old to $new
if that entry is already tagged with that tid then i just want to delete the tagmap.

i'm not really familiar with the duplicate syntax, but i'm guessing this should work if there was some way of getting the value the eid field that returned duplicate.

anyone got any ideas on this?