Mysql - Interesting SQL
Using a sub-select with an UPDATE statement:
update emailActivity_team ea, (select activityID, group_concat(contactID) as contactIDs from emailContactStatus ecs where ecs.status = 'draft' group by activityID) as t1 set ea.contactIDs = t1.contactIDs where ea.activityID = t1.activityID;
Normally, and update statement consist of only one table. This SQL consists of two tables. The second table is created by a sub-select statement. This SQL also join the two tables and update the first table using values from second table.
page revision: 1, last edited: 21 Nov 2008 15:18