delete 与 left join的问题

LEFT JOIN 的一个问题解决办法

今天在一个程序后台删除一个东西的时候,却出现了这个问题:


System Message: MySQL Query Error

User: admin
Time: 2007-10-20 21:08:48
Script: /k/admincp.php

[u]SQL: DELETE FROM table1 T LEFT JOIN table2 F USING(id) where F.typeid=1[/u]

Error: 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 'LEFT JOIN table2 F USING(id) where F.typeid=1' at line 1
Errno: 1064


在GOOGLE搜索了大约1个小时后,终于在一个国外网站上找到了原因,解决起来非常简单,TYYD

只需把如下sql:
DELETE FROM table1 T LEFT JOIN table2 F USING (id) where F.typeid=1
修改为如下sql:
DELETE T.* FROM table1 T LEFT JOIN table2 F USING(id) where F.typeid=1


增加一个T.*就搞定啦。。不容易啊

故障分析:因为insert、update、和delete三个参数,都只能针对一个表操作

这次的delete因为使用了left join,因此让程序造成是delete是对两个表进行操作,因此出现了这个问题。

你可能感兴趣的:(sql,mysql,PHP,SQL Server,F#)