PhPmyadmin SQL Query插入meta_key&值如果存在另一个值

时间:2014-03-10 02:32:32

标签: php mysql sql phpmyadmin insert-select

好的我正在寻找一个SQL查询来插入meta_key&特定表中的值如果存在另一个值。我正在使用wordpress数据库。

我想要一个查询在“ wp_postmeta ”表格中搜索“ qty(meta_key)”,其中包含“ 0(meta_value)”和使用meta_value“ 1

向所有帖子插入新的meta_key“ _wplp_post_front

我是phpmyadmin的新手,我真的需要帮助。

_ __ _ __ _ __ _ __ _ 的__ _ __ _ _____ UPDATE !!!
好的,我再次从第三方网站找到解决方案:

INSERT INTO wp_postmeta (meta_key, meta_value, post_id)
SELECT "_wplp_post_front", 1, post_id
 FROM wp_postmeta outside_table
 WHERE meta_key = 'qty'
 AND meta_value = '0'
 AND NOT EXISTS 
(SELECT * FROM wp_postmeta
WHERE post_id = outside_table.post_id
AND meta_key = "_wplp_post_front"
AND meta_value = 1
)

1 个答案:

答案 0 :(得分:0)

好的我再次从第三方网站找到了解决方案:

INSERT INTO wp_postmeta (meta_key, meta_value, post_id)
SELECT "_wplp_post_front", 1, post_id
 FROM wp_postmeta outside_table
 WHERE meta_key = 'qty'
 AND meta_value = '0'
 AND NOT EXISTS 
(SELECT * FROM wp_postmeta
WHERE post_id = outside_table.post_id
AND meta_key = "_wplp_post_front"
AND meta_value = 1
)