2011-08-30 50 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