我有这个命令来获取我的wordpress网站的所有帖子ID:
SELECT post_id
FROM `wp_postmeta`
WHERE `meta_key` LIKE 'imdbID'
我希望在这个3命令中获得 NOT 的所有帖子ID:
SELECT post_id
FROM `wp_postmeta`
WHERE `meta_key` LIKE '720-link' AND `meta_value` LIKE '%/%'
SELECT post_id
FROM `wp_postmeta`
WHERE `meta_key` LIKE 'linkDVD' AND `meta_value` LIKE '%/%'
SELECT ID
FROM `wp_posts`
WHERE `post_title` LIKE '%سر%' AND `post_status` LIKE 'publish'
AND `post_type` LIKE 'post'
我怎么能找到它?
答案 0 :(得分:0)
您可以使用WHERE IN
和UNION
:
SELECT post_id
FROM `wp_postmeta`
WHERE `meta_key` LIKE 'imdbID' AND post_id NOT IN
(
SELECT post_id
FROM `wp_postmeta`
WHERE (`meta_key` LIKE '720-link' OR `meta_key` LIKE 'linkDVD') AND
`meta_value` LIKE '%/%'
UNION
SELECT ID
FROM `wp_posts`
WHERE `post_title` LIKE '%سر%' AND `post_status` LIKE 'publish' AND
`post_type` LIKE 'post'
)