'Asql select join and delete together

table master

|  id  |   user  |
|  1   |  user1  |
|  3   |  user2  |
|  4   |  user3  |

table ver

| id_v |  value  |
|  2   |  value1 |
|  3   |  value2 |

I must delete id_v 2 on table ver

I' have this query

DELETE FROM `ver` WHERE id_v in (SELECT v.id_v
FROM master m
RIGHT JOIN ver v
ON m.id = v.id_v
WHERE m.id IS NULL)

but this is the error

You can't specify target table 'ver' for update in FROM clause



Solution 1:[1]

It could be done using the following

delete 
v
from ver v
left join master m on m.id = v.id_v
where m.id is null

Demo

Solution 2:[2]

Try this

DELETE FROM `ver` WHERE id_v in ( SELECT id_v from
(SELECT v.id_v FROM master m
RIGHT JOIN ver v
ON m.id = v.id_v
WHERE m.id IS NULL) as temp )

Solution 3:[3]

You can't use a subquery of table ver to delete something from table ver itself.

You mean this?

delete from ver where id_v is null;

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Anik Islam Abhi
Solution 3 Yang