ViaThinkSoft CodeLib
Dieser Artikel befindet sich in der Kategorie:
CodeLib → Programmierhilfen → MySQL
# Copy row with id=1 from table_a to table_b
INSERT INTO `table_b` SELECT * FROM `table_a` WHERE id = 1;
# Other variant:
INSERT INTO `table_b` (`id`, `field1`, `field2`)
SELECT `table_a`.`id`, `table_a`.`field1`, `table_a`.`field2` FROM `table_a` where `id` = 1;
# Delete row with id=1 from table_a if it does already exists at table_b:
DELETE FROM `table_a` WHERE `table_a`.`id` = 1 AND EXISTS (SELECT * FROM `table_b` WHERE `table_a`.`id` = `table_b`.`id`);
Tested with MySQL 5.1!
Daniel Marschall
ViaThinkSoft Mitbegründer
ViaThinkSoft Mitbegründer