简体   繁体   中英

Delete a Select Inner Join Query result

SELECT yturl from ytpointadder a
JOIN watched b on b.watchedyt = a.yturl AND b.ip = a.ip
Group by a.ip;

I want to delete the result of the query for exp this query result is :

yturl ip id
eY5WRONGXDI 197.XX.XX.XXX 1

Though i want to delete it from ytpointadder. I tried :

DELETE from ytpointadder a
JOIN watched b on b.watchedyt = a.yturl AND b.ip = a.ip
Group by a.ip;

You can't specify same target table for update (delete) in FROM clause. So you have to use another outer query.

Try:

DELETE FROM ytpointadder
WHERE yturl IN  ( SELECT t.yturl FROM (SELECT a.yturl, a.ip from ytpointadder a
                                     JOIN watched b on b.watchedyt = a.yturl AND b.ip = a.ip
                                     Group by a.ip 
                                     ) as t 
                 ) ;

try this

DELETE FROM ytpointadder
WHERE yturl IN
( 
SELECT a.yturl from  ytpointadder a
JOIN watched b on b.watchedyt = a.yturl AND b.ip = a.ip
Group by a.ip;)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM