0

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

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

1 回答 1

2

如果可以加入它们,则可以从多个表中删除。在你的情况下是这样的。尝试

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'
于 2013-10-29T11:38:59.427 回答