我有一个 wp_posts 和 wp_icl_translations 表格 wp_posts.ID 和 wp_icl_translations.trid STRONG>。我想排除那些已有翻译的帖子。 以下查询将检索我实际要排除的所有行。
SELECT p.ID,
p.post_title
FROM wp_posts AS p
JOIN wp_icl_translations AS t
ON p.ID= t.trid
WHERE p.post_type = '{$type}' AND
p.post_status = 'publish' AND
t.language_code='en' AND
t.element_type='post_post'
ORDER BY post_title;
答案 0 :(得分:1)
使用LEFT JOIN
并选择IS NULL
。
SELECT p.ID,
p.post_title
FROM wp_posts AS p
LEFT JOIN wp_icl_translations AS t ON p.ID= t.trid
WHERE p.post_type = '{$type}' AND
p.post_status = 'publish' AND
t.trid IS NULL
ORDER BY post_title;
答案 1 :(得分:0)
尝试(未测试)
使用NOT <>
条件
SELECT p.ID,p.post_title
FROM wp_posts AS p
INNER JOIN wp_icl_translations AS t
ON p.ID= t.trid
WHERE p.post_type = '{$type}' AND
p.post_status = 'publish' AND
t.language_code <>'en' AND
t.element_type='post_post'
ORDER BY post_title;
或
带有LEFT JOIN
的 IS NULL
SELECT p.ID,p.post_title
FROM wp_posts AS p
LEFT JOIN wp_icl_translations AS t
ON p.ID= t.trid
WHERE p.post_type = '{$type}' AND
p.post_status = 'publish' AND
t.trid IS NULL
ORDER BY post_title;
答案 2 :(得分:0)
我会说这样的话;使用(NOT)IN运算符。但是可能有一个更好的解决方案(性能不应该那么好,也没有经过测试)。
SELECT ID,
post_title
FROM wp_posts
WHERE ID NOT IN
(
SELECT p.ID
FROM wp_posts AS p
JOIN wp_icl_translations AS t
ON p.ID= t.trid
WHERE p.post_type = '{$type}' AND
p.post_status = 'publish' AND
t.language_code='en' AND
t.element_type='post_post'
)
ORDER BY post_title;