1

i have table VIDEO with cols (url, title, desc, ...) and table FAVORITE with cols(fav_url, thumb).

when i try to delete rows from both tables using:

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

i get error.

is there any way to do this job executing one query?

Eugene Yarmash
  • 142,882
  • 41
  • 325
  • 378
daniel.tosaba
  • 2,503
  • 9
  • 36
  • 47

2 Answers2

2

Try:

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%')
Eugene Yarmash
  • 142,882
  • 41
  • 325
  • 378
1

EDIT TRY THIS NOW

YOU CANT ACTUALLY DO THIS TYPE OF DELETE QUERY WHEN YOU HAVE A SUB QUERY LIKE YOU DO. Read this article which explains more in detail.

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
Community
  • 1
  • 1
Robbie Tapping
  • 2,516
  • 1
  • 17
  • 18