-3

我有以下 SELECT 会返回所有在 WordPress 中发布内容的用户:

SELECT * FROM wp_users WHERE ID IN (SELECT DISTINCT userid FROM qa_posts)

哪个 SELECT 会做相反的事情?(返回所有从未发布过的用户)

NOT IN 没有用!

==================

SELECT * FROM `wp_users` WHERE 1

显示第 0 - 191 行(总共 192 行,查询耗时 0.0004 秒)

SELECT * FROM wp_users WHERE ID IN (SELECT DISTINCT userid FROM qa_posts)

显示第 0 - 86 行(总共 87 行,查询耗时 0.0012 秒)

SELECT * FROM wp_users WHERE ID NOT IN (SELECT DISTINCT userid FROM qa_posts)

MySQL 返回一个空的结果集(即零行)。(查询耗时 0.0055 秒)

4

1 回答 1

2

有什么比说不更复杂的吗?

SELECT * FROM wp_users WHERE ID NOT IN (SELECT DISTINCT userid FROM qa_posts)

好的,试试这个作为替代

SELECT u.*
FROM wp_users u
LEFT JOIN qa_posts p on u.id = p.userid
WHERE p.userid is null;
于 2013-06-30T19:39:26.317 回答