2012-09-29 77 views
2

我收到:子查詢的MySQL中的限制會產生誤差

[Err] 1235 - This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'

在執行以下查詢:

UPDATE account.account 
SET STATUS = 'BLOCK' 
WHERE 
    id IN (
     SELECT 
      p.account_id 
     FROM 
      log.log 
     LEFT JOIN player.player p ON (p.id = log.who) 
     WHERE 
      vnum = 71054 
     AND how = 'BUY' 
     GROUP BY 
      log.`who` 
     HAVING 
      COUNT(log.who) > 2 
     LIMIT 10 
    ); 

是否有posibility改寫這個查詢因此MySQL可以執行它?

回答

4

的解決方案是對加入一個子查詢,而不是使用IN()。該INNER JOIN只會account匹配的IDS從有限的子查詢返回行。然後可以做UPDATE沒有WHERE條款。

Update 
    account.account AS account 
    INNER JOIN (
     SELECT 
      p.account_id 
     FROM 
      log.log 
      LEFT JOIN player.player p ON (p.id = log.who) 
     WHERE 
      vnum = 71054 
      AND how = 'BUY' 
     GROUP BY log.`who` 
     HAVING COUNT(log.who) > 2 
     LIMIT 10 
    ) subq ON account.id = subq.id 
SET STATUS='BLOCK' 

要驗證將被修改的行,使用SELECT第一:

SELECT 
    account.* 
FROM 
    account.account 
    INNER JOIN (
      SELECT 
       p.account_id 
      FROM 
       log.log 
       LEFT JOIN player.player p ON (p.id = log.who) 
      WHERE 
       vnum = 71054 
       AND how = 'BUY' 
      GROUP BY log.`who` 
      HAVING COUNT(log.who) > 2 
      LIMIT 10 
     ) subq ON account.id = subq.id 
+0

謝謝,這工作:-) – Sapp

+0

@Sapp。 。 。如果它的工作,記得要接受的答案。 –

+0

@GordonLinoff我不認爲等待期尚未屆滿時... –