是否可以将这三个查询合并为一个?
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'
答案 0 :(得分: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'