gpt4 book ai didi

mysql - 使用 1 个查询从三个不同的表中删除?

转载 作者:行者123 更新时间:2023-11-29 08:20:02 24 4
gpt4 key购买 nike

是否可以将这三个查询合并为一个?

DELETE FROM `users exercises` WHERE `date` = '$date' AND `userid` = '$user->id'
DELETE FROM `users foods` WHERE `date` = '$date' AND `userid` = '$user->id'
DELETE FROM `users check-ins` WHERE `date` = '$date' AND `userid` = '$user->id'

最佳答案

如果可以连接多个表,则可以从多个表中删除它们。你的情况确实如此。尝试一下

DELETE e, f, c
FROM `users exercises` e
inner join `users foods` f on f.userid = e.userid and f.`date` = e.`date`
inner join `users check-ins` c on c.userid = e.userid and c.`date` = e.`date`
WHERE e.`date` = '$date'
AND e.userid = '$user->id'

关于mysql - 使用 1 个查询从三个不同的表中删除?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19657173/

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