我试过执行这个sql语句
delete
from reclamo r
where exists ( select 1 from reclamo r
join cliente c on r.cod_cliente = c.cod_cliente
join localidad l on c.cod_localidad = l.cod_localidad
where l.descripcion = 'San Justo');
删除'San justo'镇客户提出的所有索赔 但它显示“错误代码:1064。您的SQL语法有错误;请查看与您的MySQL服务器版本对应的手册,以便在'r附近使用正确的语法 存在的地方(从reclamo r中选择1 在r.cod_cliente'第2行加入cliente c“ 有谁知道如何解决这些错误?
sqlfiddele:http://sqlfiddle.com/#!2/b2771
答案 0 :(得分:3)
如果你正在使用别名......你必须告诉实际要删除的内容(可能这是因为表别名通常只是需要在多个表语法中...你可以省略完全别名):
mysql> delete from tablename r;
ERROR 1064 (42000): 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 'r' at line 1
mysql> delete r from tablename r;
Query OK, 0 rows affected (0.00 sec)
参见als the manual:
请注意
如果声明表的别名,则在引用表时必须使用别名: 删除t1 FROM测试AS t1,test2 WHERE ...
答案 1 :(得分:1)
不要使用别名。这是等效的逻辑,并且可以正常工作。
delete from reclamo
where cod_cliente in
(select cod_cliente
from cliente c join localidad l on c.cod_localidad = l.cod_localidad
where l.descripcion = 'San Justo');