2013-12-20 51 views
0

我一直在處理一個查詢,該查詢採用表記錄的子集並更新它們,但不知何故,我是不能讓它工作,它給我的錯誤#1093 - You can't specify target table 'members' for update in FROM clause無法運行查詢給出mySQL錯誤#1093 - 您無法在FROM子句中指定目標表「成員」進行更新

下面是該查詢:

UPDATE members set is_deleted = 1 
    WHERE EXISTS 
    (SELECT m1.member_id FROM members as m1 
      WHERE m1.member_id NOT IN 
       (select member_id 
        from membership_payment_profiles 
        WHERE (next_date_to_charge > "2012-12-31 00:00:00" 
        or next_date_to_charge is null) 
      order by next_date_to_charge DESC 
) 
and m1.joined_on < "2012-12-31 00:00:00" 
) 

回答

2

嘗試此查詢

update members m1 set m1.is_deleted=1 where m1.member_id not in (select distinct member_id 
        from membership_payment_profiles 
        WHERE (next_date_to_charge > "2012-12-31 00:00:00" 
        or next_date_to_charge is null) order by next_date_to_charge DESC) and m1.joined_on < "2012-12-31 00:00:00"; 
相關問題