UPDATE и SELECT
Author:

Обновлять одну таблицу с выборкой из другой просто. Вот реально работающий случай в триггере "user.tr_user_after_update":

UPDATE user_prize_block,prize_fund SET user_prize_block.block="U"
WHERE
 user_prize_block.fund=prize_fund.id AND
 prize_fund.block_same_ip!="N" AND
 prize_fund.block_same_ip_monitor_ip_changes="Y" AND
 prize_fund.active="Y" AND
 user_prize_block.id=NEW.id AND user_prize_block.block="N"

Ещё по теме с LEFT JOIN читать тут: https://stackoverflow.com/questions/1262786/mysql-update-query-based-on-select-query

UPD. Ещё более ранний пример с LEFT JOIN'ом, в mySQL-функции "refresh_company_active_banner".

  UPDATE company
    LEFT JOIN banner ON banner.company=company.id AND banner.active="Y" AND
     (banner.active_campaign="Y" OR 
      (slimit="D" AND start<=CURRENT_DATE AND expire>=DATE_SUB(CURRENT_DATE, INTERVAL 3 MONTH)))
   SET has_active_banner_campaign=IF(banner.id IS NULL,"N","Y")
   WHERE IF(comp_id>0 AND comp_id IS NOT NULL, company.id=comp_id, 1);
Tags Tags:  mysql, select, update
]]>
]]>

Send by E-mailSend by E-mail   Print versionPrint version
Comments(0)

No comments yet… Be the first to leave comment on this topic!

or
Also you may sign in using:
]]> ]]>