删除连接嵌套查询

时间:2011-04-21 20:39:50

标签: mysql

我有桌子VIDEO和cols(url,title,desc,...)和桌子FAVORITE和cols(fav_url,thumb)。

当我尝试使用以下方法从两个表中删除行时

delete from video join favorite on video.url=favorite.fav_url
  where url in (select url from video where title like '%thumb%')

我收到错误。

有没有办法执行一个查询?

2 个答案:

答案 0 :(得分:2)

尝试:

DELETE t1, t2 FROM video t1 JOIN favorite t2 ON t1.url=t2.fav_url
WHERE url IN
    (SELECT url FROM (SELECT * FROM video) t3 WHERE title LIKE '%thumb%')

答案 1 :(得分:1)

编辑现在尝试

当你有一个像我一样的小问题时,你实际上可以做这种类型的删除查询。 阅读这篇文章,详细解释。

MySQL Error 1093 - Can't specify target table for update in FROM clause

DELETE video, favorite 
    FROM video
    JOIN favorite 
        ON video.url = favorite.fav_url
    JOIN (SELECT DISTINCT url 
                  FROM video 
                  WHERE title like '%thumb%') tt ON video.url = tt.url