2017-09-26 87 views
0

是否有可能執行sql刪除查詢foreach user_id在表中? 我可以得到SELECT user_id FROM用戶 所有的user_id這樣我就可以刪除除最後所有的RAW與執行SQL刪除查詢foreach user_id

DELETE FROM accounts 
WHERE id IN (select * from (SELECT id 
FROM accounts 
WHERE user_id = 150192618395339835 
     AND site = 'https://www.paypal.com' 
     AND time_added < (SELECT Max(time_added) 
         FROM accounts 
         WHERE user_id = 150192618395339835 
           AND site = 'https://www.paypal.com') 
ORDER BY time_added ASC) as t) 

如何傳遞所有的user_id刪除查詢?

回答

1

嘗試用

WHERE user_id in (SELECT u.user_id FROM users u) 

而且所有查詢:

DELETE FROM accounts 
WHERE id IN (select * from (SELECT id 
FROM accounts 
WHERE user_id in (SELECT u.user_id FROM users u) 
     AND site = 'https://www.paypal.com' 
     AND time_added < (SELECT Max(time_added) 
         FROM accounts 
         WHERE user_id = 150192618395339835 
           AND site = 'https://www.paypal.com') 
ORDER BY time_added ASC) as t) 
+0

什麼關於第二個在哪裏呢? –