mysql-我无法在sql删除中使用别名
作者:互联网
我试过执行这个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');
用于删除“圣胡斯托”镇的客户提出的所有索赔
但显示“错误代码:1064.您的SQL语法有错误;请查看与您的MySQL服务器版本相对应的手册,以获取在’r’附近使用的正确语法
存在的地方(从撤回中选择1
在第2行的r.cod_cliente’上加入cliente c“
有人知道我该如何解决这些错误?
sqlfiddele这里:http://sqlfiddle.com/#!2/b2771
解决方法:
如果您使用别名…,您必须告诉您实际删除的内容(可能是因为表别名通常仅在多种表语法中才需要…您可以完全省略别名):
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:
Note
If you declare an alias for a table, you must use the alias when referring to the table:
DELETE t1 FROM test AS t1, test2 WHERE …
标签:sql-delete,sql,mysql 来源: https://codeday.me/bug/20191030/1969070.html