PhPmyadmin SQL Query to insert meta_key & value IF another value exist

℡╲_俬逩灬. 提交于 2019-12-08 10:19:33

问题


Ok I am looking for an sql query to insert meta_key & value in a specific table IF another value exist. I am using wordpress database.

I want a query to search the "wp_postmeta" table for "qty (meta_key)" with "0 (meta_value)" and insert to all those posts a new meta_key "_wplp_post_front" with meta_value "1"

I am new with phpmyadmin and I really need help.

________________________UPDATE!!!
Ok once again i have found the solution from third party website:

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:


Ok once again i have found the solution from third party website:

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
)


来源:https://stackoverflow.com/questions/22291159/phpmyadmin-sql-query-to-insert-meta-key-value-if-another-value-exist

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!