我正在尝试删除我通过管理员帐户创建的网站中某个人的所有记录。查询如下:
DELETE FROM users u, user_address ua, pending_order po, product_catalogue pc
WHERE u.user_id = ua.user_id
AND ua.user_id = po.user_id
AND po.user_id = pc.user_id
AND u.user_id = '$user_id'
$user_id
是从表单中的 $_POST['user_id']
获取的。
每当我运行它时,我总是收到此错误
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'u, user_address ua, pending_order po, product_catalogue pc WHERE u.user_id = ua.' at line 1
这里出了什么问题?
最佳答案
您必须为每个表运行一个删除语句:
delete from users where user_id = '$user_id';
delete from user_addresses where user_id = '$user_id';
delete from pending_order where user_id = '$user_id';
delete from product_catalogue where user_id = '$user_id';
关于mysql - 无法从多个表中删除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25097542/