大家可以帮助我解决这个无效的查询吗?
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 :(得分: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 = ?