gpt4 book ai didi

php - 从多个表中删除不起作用

转载 作者:行者123 更新时间:2023-11-29 21:57:51 25 4
gpt4 key购买 nike

场景:有4张表[A,B,C,D,E]。我想在一个查询中删除所有这些。我正在应用以下查询。

$con=mysqli_connect("localhost","root","","db")
$del="DELETE a,b,c,d,e FROM `A` as a INNER JOIN `B` as b INNER JOIN `C` as c
INNER JOIN
`D` as d INNER JOIN `E` as e ON a.user_id=b.user_id AND a.user_id=c.user_id
AND a.user_id=d.user_id AND a.user_id=e.user_id
WHERE login.user_id= '25'";
$que=mysqli_query($con,$del)
if($del){
echo "Its done";
}
else{
echo mysqli_error($con);}

当每个表中都有针对该 ID 的数据时,删除效果很好。但是,当某些表中没有数据(例如 D 和 E 中)时,查询将不起作用,并且不会删除任何内容。我认为这是因为我在“ON”之间放置了 AND 运算符。我对sql了解不多。所以,请有人帮助我。另一件事是,打印完成后不会出现任何错误。希望这对您有意义。提前致谢。

最佳答案

试试这个

$del="DELETE a,b,c,d,e 
FROM `A` as a
LEFT OUTER JOIN `B` as b ON a.user_id=b.user_id
LEFT OUTER JOIN `C` as c ON a.user_id=c.user_id
LEFT OUTER JOIN `D` as d ON a.user_id=d.user_id
LEFT OUTER JOIN `E` as e ON a.user_id=e.user_id
WHERE login.user_id= '25'";

关于php - 从多个表中删除不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32963700/

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