我无法更新表格。我应该如何写更新表

时间:2011-11-03 18:09:02

标签: mysql

update kothari_kem.companyinfo ci 
set ci.viewsource = "" 
where ci.recid in (
    SELECT c.recid 
    FROM kothari_kem.companyinfo c 
    where (c.contactperson = NULL or c.contactperson = "") 
    AND (c.viewsource = NULL or c.viewsource = "Y")
)

1 个答案:

答案 0 :(得分:0)

试试这个:

CREATE TEMPORARY TABLE tt (id INT);
INSERT INTO tt
    SELECT c.recid 
    FROM kothari_kem.companyinfo c 
    where (c.contactperson IS NULL or c.contactperson = "") 
    AND (c.viewsource IS NULL or c.viewsource = "Y");
UPDATE kothari_kem.companyinfo ci 
SET ci.viewsource = "" 
WHERE ci.recid in
    (SELECT id FROM tt)

无论如何,我认为您的查询可以重写为

UPDATE kothari_kem.companyinfo ci 
SET ci.viewsource = "" 
WHERE (ci.contactperson IS NULL or ci.contactperson = "") 
  AND (ci.viewsource IS NULL or ci.viewsource = "Y")