在mysql命令中找到重复的行

时间:2016-06-14 09:41:34

标签: mysql wordpress duplicates

我有这个命令来获取我的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'

我怎么能找到它?

1 个答案:

答案 0 :(得分:0)

您可以使用WHERE INUNION

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'
)