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?

2 Answers 2

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%')
Sign up to request clarification or add additional context in comments.

1 Comment

#1093 - You can't specify target table 't1' for update in FROM clause
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

7 Comments

#1093 - You can't specify target table 'V' for update in FROM clause
WHAT THE? Did you use the exact code above? did you have anything in the Query window at the same time? I just wrote a query nearly identitical and got no error at all.
What version of mysql are you using?
ur edited version: #1093 - You can't specify target table 'video' for update in FROM clause
Found a URL that i have added to my answer, it explains why you cant do that type of update when you have a Subquery like you do.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.