2011-08-30 61 views
1

我想从表中删除,使用其他表的联接。删除引用多个表不能在MYSQL上工作

我的SQL如下:

DELETE FROM `threadsread` 
USING `mybb_threads` t 
WHERE 
threadsread.tid=threads.tid and threadsread.uid in (2111, 2564, 2326, 2510) 
and mybb_threads.fid=30 

,但我得到了以下错误:

1109 - Unknown table 'mybb_threadsread' in MULTI DELETE

这些都不是意见,一切都是真实的表。我可以使用类似的SQL运行选择,没有任何问题。

回答

1

我设法得到它用下面的SQL工作:

delete FROM threadsread 
USING threadsread 
inner join threads 
WHERE 
threadsread.tid=threads.tid and threadsread.uid in (2111, 2564, 2326, 2510) 
and threads.fid=30 

感谢您的帮助M. CA

1

请看看下面从Mysql.com

For the first multiple-table syntax, only matching rows from the tables listed before the FROM clause are deleted. For the second multiple-table syntax, only matching rows from the tables listed in the FROM clause (before the USING clause) are deleted. The effect is that you can delete rows from many tables at the same time and have additional tables that are used only for searching:

DELETE t1, t2 FROM t1 INNER JOIN t2 INNER JOIN t3 WHERE t1.id=t2.id AND t2.id=t3.id; Or:

DELETE FROM t1, t2 USING t1 INNER JOIN t2 INNER JOIN t3 WHERE t1.id=t2.id AND t2.id=t3.id; These statements use all three tables when searching for rows to delete, but delete matching rows only from tables t1 and t2.

+0

这不就是我在我的SQL代码上做什么? – Emerson