gpt4 book ai didi

php - SQL:使用联接从多个表中删除

转载 作者:行者123 更新时间:2023-11-29 13:29:35 26 4
gpt4 key购买 nike

如果三个表中的每一个都产生结果,则以下内容将起作用,但是如果其中只有一个表没有任何内容,那么它会中断查询并且不会删除任何内容。有没有办法保护这个查询,这样如果三个表中只有一个有结果,它们就会被删除?

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'

最佳答案

你有“用户”表吗?如果是这样,那么你可以这样写:

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

关于php - SQL:使用联接从多个表中删除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19658660/

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