打印

超难的MySQL问题

超难的MySQL问题

如果table1的某一行的a 与table2的c对应,就删除table1的这一行。

table1
a   | b
-----
1   | 100
2   | 200

table2
c   |
----
1   |

在SQL server 里面可以这样写到:
delete table1 from table1 a join table2 b on a.a=b.c;

但在MySQL里面就不行,应该怎么改?谢谢!

TOP

[code:1]
DELETE
    FROM table1 t1 LEFT JOIN table2 t2 ON t1.a = t2.c
    WHERE t1.a = xxx
[/code:1]

TOP

出现问题:

mysql> DELETE
    ->     FROM table1 t1 LEFT JOIN table2 t2 ON t1.a = t2.c ;
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 'LEFT
JOIN table2 t2 ON t1.a = t2.c' at line 2
mysql>

TOP

http://www.google.com/url?sa=t&ct=res&cd=1&url=http%3A%2F%2Fbugs.mysql.com%2Fbug.php%3Fid%3D2171&ei=MmFIRIDkOoiUogLut_2iBQ&sig2=mgf7pnaBw7jTXvnxh9Abcw
MySQL居然不支持连接删除
http://dev.mysql.com/doc/refman/5.0/en/delete.html
DELETE t1, t2 FROM t1, t2, t3 WHERE t1.id=t2.id AND t2.id=t3.id;

Or:

DELETE FROM t1, t2 USING t1, t2, t3 WHERE t1.id=t2.id AND t2.id=t3.id;

推荐使用PostgreSQL了

TOP

网上有这样回复,不知道运行效率怎样?

delete from t1 where t1.a in (select t2.c from t2);

虚拟主机一般只支持 MySQL或 SQL Server。无奈~

TOP

MySQL 不支持查询嵌套,所以 SQL 语句要构思严谨……………

好像 5 支持嵌套了?
不想要 ID 了请找我。

TOP

MySQL用InnoDB做Table的Engine的话就持连接删除了
滚滚长江东逝水, 浪花淘尽英雄. 是非成败转头空. 青山依旧在, 几度夕阳红. 白发渔憔江渚上, 惯看秋月春风. 一壶浊酒喜相逢. 古今多少事, 咳~, 偶用Gentoo. -------------------------------------------------- 偶的Blog

TOP