mysql - 无法从多个表中删除

标签 mysql sql

我正在尝试删除我通过管理员帐户创建的网站中某个人的所有记录。查询如下:

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/

相关文章:

sql - shift id's of table alike (id = id + 1) 其中 id 是主键

sql - Postgre/SQL 递归查询

php - 使用 MySQL 数据库中的计数填充列表 PHP

PHP 和多个 MySQL 连接

php - cakephp 使用 hasAndBelongsToMany 进行分页查询

php - 带有OR或AND或全文的表中的MySQL搜索关键字与[duplicate]匹配

php - 在 php MySQL WHERE 子句中使用数组复选框值

mysql - 删除并加入

MySQL - 创建用户定义函数 (UDF) 时出现问题

sql - 从另一个表的多行中生成 1 行