2012-03-07 76 views
0

夥計們你能幫我這個不工作查詢嗎?在mysql的左連接中使用限制

UPDATE DB_1 
left join blacklist as blk 
    on DB_1.last_email=blk.email 
SET DB_1.sampling = ? 
WHERE blk.email IS NULL 
    and DB_1.sampling IS NULL 
LIMIT "+slot; 

我需要在當時更新25k行,但這樣做是行不通的。我如何創建一個可以工作的查詢?我正在考慮放棄左連接並使用IN進行連接。

+0

檢查這個答案:有沒有在替代有限制嗎?(http://stackoverflow.com/questions/7940440/IS-有-AN-替代到在與 - 極限/ 7947425#7947425) – 2012-03-07 12:05:55

回答

1

您是否要更新DB_1中不在blacklist中的行?

你可以試試:

UPDATE 
    DB_1 
SET 
    DB_1.sampling = ? 
WHERE 
    NOT EXISTS 
     (SELECT * 
     FROM blacklist AS blk 
     WHERE blk.email = DB_1.last_email 
    ) 
ORDER BY 
    <something> 
LIMIT 
    <whatever> 

或:

UPDATE 
     DB_1 AS upd 
    JOIN 
     (SELECT t.PK 
      FROM 
        DB_1 AS t 
       LEFT JOIN 
        blacklist AS blk 
         ON blk.email = t.last_email 
      WHERE 
       blk.email IS NULL 
      ORDER BY 
       <something> 
      LIMIT 
       <whatever> 
     ) AS lim 
      ON lim.PK = upd.PK 
SET 
    upd.sampling = ?