前言
一些小技巧,可以帮助我们解决很多麻烦的事情。
更新自身表
UPDATE `table_a` SET `table_a`.`key` = ‘name’ WHERE `table_a`.`key` IN (SELECT b.`key` FROM `table_a` AS a JOIN `table_b` AS b ON a.`key` = b.`key`);
然而,MySQL
并不支持,所以可以换另外一种。
UPDATE `table_a` AS a JOIN (SELECT b.`key` FROM `table_a` AS a JOIN `table_b` AS b ON a.`key` = b.`key`) AS b ON a.`key` = b.`key` SET a.`key` = ‘name’;
优化子查询:
使用JOIN
语句来优化。
使用聚合查询
暂无好的想法~
-- EOF --
本文转载自IMJCW
原文链接:JOIN使用技巧