将Update / Join转为查询

时间:2013-10-20 21:31:58

标签: mysql

我有

Update2 `Table1` AS T1 Inner Join `Table2` As T2
On T2.`Name` = T1.Name
Set T1.`ParentID` = T2.`ID`

我想先检查一下,在长周末后让大脑冻结,帮助赞赏。

我基本上想先检查一下

Select FieldA, concat(FieldC,', ',FieldD) `Table1` AS T1 Inner Join `Table2` As T2
on T2.`Name` = T1.Name
Set T1.`ParentID` = T2.`ID`

确保我得到了正确的结果。

1 个答案:

答案 0 :(得分:1)

等效的SELECT可以是:

SELECT T1.`ParentID` = T2.`ID`
FROM `Table1` AS T1 Inner Join `Table2` AS T2
  ON T2.`Name` = T1.Name

pt-query-digest是一个将UPDATE转换为SELECT的工具示例,因此它可以运行EXPLAIN。