我在sql delete´t可以使用别名

时间:2021-06-11 22:45:02

I tried execute this sql sentence

我尝试执行这个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');

for remove all the claims made by customers of the town of 'San justo' but it says "Error Code: 1064. 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 where exists ( select 1 from reclamo r join cliente c on r.cod_cliente' at line 2" anyone know how I can fix these errors?

删除所有由“San justo”镇的客户提出的索赔要求,但上面写着“错误代码:1064”。您的SQL语法有错误;检查与你的MySQL服务器版本对应的手册,以便使用接近“r”的正确语法(从reclamo r中选择1,在r上加入cliente c)。cod_cliente在第2行有人知道我怎么修正这些错误吗?

sqlfiddele here: http://sqlfiddle.com/#!2/b2771

sqlfiddele:http://sqlfiddle.com/ ! 2 / b2771

2 个解决方案

#1


3  

If you're using aliases... ÿou have to tell what to actually delete (probably this is because table aliases are usually only needed in multiple table syntax... you could just omit the alias altogether):

如果你使用别名…您必须告诉实际要删除什么(可能这是因为表别名通常只需要在多个表语法中……)你可以完全省略别名):

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)

See als the manual:

看到als手册:

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 ...

注意,如果您声明一个表的别名,那么在引用表时必须使用别名:将测试中的t1删除为t1, test2,其中…

#2


1  

Don't use an alias. This is equivalent logic and will work fine.

不要使用别名。这是等价的逻辑,将会很好地工作。

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');

#1


3  

If you're using aliases... ÿou have to tell what to actually delete (probably this is because table aliases are usually only needed in multiple table syntax... you could just omit the alias altogether):

如果你使用别名…您必须告诉实际要删除什么(可能这是因为表别名通常只需要在多个表语法中……)你可以完全省略别名):

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)

See als the manual:

看到als手册:

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 ...

注意,如果您声明一个表的别名,那么在引用表时必须使用别名:将测试中的t1删除为t1, test2,其中…

#2


1  

Don't use an alias. This is equivalent logic and will work fine.

不要使用别名。这是等价的逻辑,将会很好地工作。

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');