0

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

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'
4

1 回答 1

1

你有一个“用户”表吗?如果是这样,那么您可以编写如下内容:

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'
于 2013-10-29T14:27:39.427 回答