2

您好我仍在为以下代码而苦苦挣扎

INSERT INTO m4zbv_mt_cfvalues (cf_id, link_id,value) 
    SELECT 87,link_id,1
    FROM m4zbv_mt_links WHERE Upper(`link_name`) like'%#VMWARE APPLIANCE DEFAULT PASSWORDS%'
    WHERE NOT EXISTS(select cf_id, link_id from m4zbv_mt_cfvalues where cf_id=87 and link_id=m4zbv_mt_links.link_id)

这部分工作正常:

INSERT INTO m4zbv_mt_cfvalues (cf_id, link_id,value) 
    SELECT 87,link_id,1
    FROM m4zbv_mt_links WHERE Upper(`link_name`) like'%#VMWARE APPLIANCE DEFAULT PASSWORDS%'

我不确定如何m4zbv_mt_links.link_id从第一个选择中传递值以及如何集成WHERE NOT EXISTS

谢谢你的帮助

4

2 回答 2

0

它应该and代替where

INSERT INTO m4zbv_mt_cfvalues (cf_id, link_id,value) 
SELECT 87,link_id,1
FROM m4zbv_mt_links WHERE Upper(`link_name`) like'%#VMWARE APPLIANCE DEFAULT PASSWORDS%'
and NOT EXISTS
               (select cf_id, link_id 
                from m4zbv_mt_cfvalues 
                where cf_id=87 and link_id=m4zbv_mt_links.link_id)
于 2013-02-02T17:25:30.123 回答
0

如果您要做的只是避免重复,只需 INSERT IGNORE (并删除 WHERE NOT EXISTS 子句)

于 2013-02-02T17:25:57.313 回答