gpt4 book ai didi

php - 对多个行/列使用一个 UPDATE 查询

转载 作者:行者123 更新时间:2023-11-29 12:49:16 25 4
gpt4 key购买 nike

考虑到我正在执行大量条件语句,我将如何将代码放入一个 UPDATE 语句中:

    $updateTbl1 =   "UPDATE $tableNameOrig o, $tableNameTemp t SET o.customerAge = t.customerAge WHERE o.id = t.id AND (o.customerAge != t.customerAge );";
$updateTbl2 = "UPDATE $tableNameOrig o, $tableNameTemp t SET o.customerCode = t.customerCode WHERE o.id = t.id AND (o.customerCode != t.customerCode);";
$updateTbl3 = "UPDATE $tableNameOrig o, $tableNameTemp t SET o.customerName = t.customerName WHERE o.id = t.id AND (o.customerName != t.customerName);";
$updateTbl4 = "UPDATE $tableNameOrig o, $tableNameTemp t SET o.customerEmail = t.customerEmail WHERE o.id = t.id AND (o.customerEmail != t.customerEmail);";
$updateTbl5 = "UPDATE $tableNameOrig o, $tableNameTemp t SET o.customerAddress = t.customerAddress WHERE o.id = t.id AND (o.customerAddress != t.customerAddress);";
$updateTbl6 = "UPDATE $tableNameOrig o, $tableNameTemp t SET o.customerAdded = t.customerAdded WHERE o.id = t.id AND (o.customerAdded != t.customerAdded);";

(mysqli_query($con,$updateTbl1));
(mysqli_query($con,$updateTbl2));
(mysqli_query($con,$updateTbl3));
(mysqli_query($con,$updateTbl4));
(mysqli_query($con,$updateTbl5));
(mysqli_query($con,$updateTbl6));

谢谢!

最佳答案

UPDATE $tableNameOrig o
JOIN $tableNameTemp t
ON o.id = t.id
SET o.customerAge = t.customerAge,
o.customerCode = t.customerCode,
o.customerName = t.customerName,
o.customerEmail = t.customerEmail,
o.customerAddress = t.customerAddress,
o.customerAdded = t.customerAdded

你的其他条件毫无意义。

关于php - 对多个行/列使用一个 UPDATE 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25016260/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com