Aalex Gabi Aalex Gabi - 1 year ago 103
MySQL Question

DELETE FROM `table` AS `alias` ... WHERE `alias`.`column` ... why syntax error?

I tried this with 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?

Is this MySQL specific?

Answer Source

You can use SQL like this:

DELETE FROM ContactHostCommand USING `contact_hostcommands_relation` AS ContactHostCommand WHERE (ContactHostCommand.`chr_id` = 999999) LIMIT 1
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download