31

MySQLでこれを試しました:

DELETE FROM `contact_hostcommands_relation` AS `ContactHostCommand` WHERE (`ContactHostCommand`.`chr_id` = 999999) LIMIT 1

そして、私はこれを取得します:

#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

注:このクエリは自動的に生成され、条件はテーブル エイリアスに基づいています。

なぜこのエラーが発生するのですか?

where句でテーブルエイリアスを使用する方法はありますか?

これは MySQL 固有のものですか?

4

3 に答える 3

45

@Matus と @CeesTimmerman が MSSQL について述べたことは、MySQL 5.1.73 でも機能します。

delete <alias> from <table> <alias> where <alias>.<field>...
于 2014-11-14T17:37:56.603 に答える
31

次のように SQL を使用できます。

DELETE FROM ContactHostCommand 
USING `contact_hostcommands_relation` AS ContactHostCommand 
WHERE (ContactHostCommand.`chr_id` = 999999) 
LIMIT 1
于 2013-04-02T07:12:53.430 に答える
5

MySQLASの句で使用することはできません:DELETE

DELETE FROM `contact_hostcommands_relation` WHERE (`chr_id` = 999999) LIMIT 1 
于 2012-05-07T15:14:49.230 に答える