Try using an UPDATE JOIN of the table against itself
UPDATE
animal_table A
INNER JOIN
(
SELECT
category_id,summary_id,
animal_nbr,animal_amount,'00' info3
FROM animal_table
WHERE animal_type = 'special'
) B USING (category_id,summary_id)
SET
A.animal_info1 = B.animal_nbr,
A.animal_info2 = B.animal_amount,
A.animal_info3 = B.info3
WHERE
A.animal_type = 'cats' AND
A.category_id = 'foo';
Make sure that animal_table has a compound index on category_id and summary_id. If you do not have such an index, please run this:
ALTER TABLE animal_table ADD INDEX (category_id,summary_id);
UPDATE 2011-09-27 13:10 EDT
I just noticed that categrory_id 'foo' limits the dataset. Here is an updated refactoring of my answer ( I moved category_id = foo into the subquery )
UPDATE
animal_table A
INNER JOIN
(
SELECT
category_id,summary_id,
animal_nbr,animal_amount,'00' info3
FROM animal_table
WHERE animal_type = 'special'
AND category_id = 'foo'
) B USING (category_id,summary_id)
SET
A.animal_info1 = B.animal_nbr,
A.animal_info2 = B.animal_amount,
A.animal_info3 = B.info3
WHERE
A.animal_type = 'cats';
I also recommend adding this additional index to accommodate the subquery
ALTER TABLE animal_table ADD INDEX (animal_type,category_id);
Try
UPDATE Tab1 JOIN Tab2 ON Tab1.b = Tab2.b
SET Tab1.a = '3'
WHERE Tab1.c = '4'
;
Check the documentation for further information (look for 'multiple-table syntax'). An important point is:
If you use a multiple-table UPDATE statement involving InnoDB tables
for which there are foreign key constraints, the MySQL optimizer might
process tables in an order that differs from that of their
parent/child relationship. In this case, the statement fails and rolls
back. Instead, update a single table and rely on the ON UPDATE
capabilities that InnoDB provides to cause the other tables to be
modified accordingly. See Section 14.3.5.4, “FOREIGN KEY Constraints”.
You may check a similar example on SQLFiddle.
Best Answer
Use multiple-table DELETE syntax: