MySQL DELETE FROM `table` AS `alias` ... WHERE `alias`.`column` ... 为什么语法错误?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10484532/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
DELETE FROM `table` AS `alias` ... WHERE `alias`.`column` ... why syntax error?
提问by Aalex Gabi
I tried this with MySQL:
我用 MySQL 试过这个:
DELETE FROM `contact_hostcommands_relation` AS `ContactHostCommand` WHERE (`ContactHostCommand`.`chr_id` = 999999) LIMIT 1
And I get this:
我明白了:
#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 'WHERE (`ContactHostCommand`.`chr_id` = 999999) LIMIT 1' at line 1
Note:This query is automatically generated and conditions are based on table aliases.
注意:此查询是自动生成的,条件基于表别名。
Why I get this error?
为什么我收到这个错误?
Is there any way to use table aliases in where clause?
有没有办法在 where 子句中使用表别名?
Is this MySQL specific?
这是 MySQL 特定的吗?
回答by Rafael Barros
What @Matus and @CeesTimmerman said about MSSQL, works in MySQL 5.1.73 too:
@Matus 和 @CeesTimmerman 所说的关于 MSSQL 的内容也适用于 MySQL 5.1.73:
delete <alias> from <table> <alias> where <alias>.<field>...
回答by Sarunas
You can use SQL like this:
您可以像这样使用 SQL:
DELETE FROM ContactHostCommand
USING `contact_hostcommands_relation` AS ContactHostCommand
WHERE (ContactHostCommand.`chr_id` = 999999)
LIMIT 1
回答by adrien
You cannot use AS
in a DELETE
clause with MySQL :
你不能AS
在DELETE
MySQL的子句中使用:
DELETE FROM `contact_hostcommands_relation` WHERE (`chr_id` = 999999) LIMIT 1