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: 1227280719|%e %b %Y, %H:%M %Z (%O ago)
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License