Mysql 从表中获取未填写行的所有用户

Mysql 从表中获取未填写行的所有用户,mysql,sql,wordpress,Mysql,Sql,Wordpress,特别是wordpress中的用户元表。我正在尝试获取所有没有特定元密钥的用户 比如说 用户id-1 2 3 4 2 1 meta_键-a a c b met_值-等 因此,在这个例子中,我想得到所有在数据库中没有meta键为b的条目的用户。不包括3和1。。。sql查询应该只返回用户2和4。我知道如何以另一种方式轻松地实现这一点,找到所有具有B元键的用户,但我不知道如何编写一个查询,以获得所有其他不具有B元键的用户 谢谢一种方法不是EIXST: 如果没有单独的用户表: select distinc

特别是wordpress中的用户元表。我正在尝试获取所有没有特定元密钥的用户

比如说

用户id-1 2 3 4 2 1

meta_键-a a c b

met_值-等

因此,在这个例子中,我想得到所有在数据库中没有meta键为b的条目的用户。不包括3和1。。。sql查询应该只返回用户2和4。我知道如何以另一种方式轻松地实现这一点,找到所有具有B元键的用户,但我不知道如何编写一个查询,以获得所有其他不具有B元键的用户

谢谢

一种方法不是EIXST:

如果没有单独的用户表:

select distinct m.user_id
from metatable m
where not exists (select 1
                  from metatable m2
                  where m2.meta_key = 'b' and m2.user_id = m.user_id
                 );

我假设所讨论的元表是wp_usermeta。

你能分享你如何找到所有元键为B的用户吗?从users_meta中选择*其中meta_key='B'I将添加一个调整,并将查询的选择部分改为SELECT distinct u.user\u id,这样我们就不会得到重复的。是的,这是wp_usermeta表,这对我来说不起作用,这是我的最终sql选择u.*从wp_用户u不存在的地方从wp_用户meta m选择1,其中meta_键='\u sfwd-course_progress'和m.user_id=u.id@布兰克473。您的评论中的查询看起来是正确的。它怎么不起作用呢?不知道,我甚至试过这个选择*从wp_用户u不存在的地方选择*从wp_用户meta m其中m.meta_key=''sfwd-course_progress'和m.user_id=u.id。。。。但是没有卢卡姆,我把这部分做对了吗$rs=mysql\u query$sql;而$data=mysql_fetch_assoc$rs{echo$data['email'];}
select distinct m.user_id
from metatable m
where not exists (select 1
                  from metatable m2
                  where m2.meta_key = 'b' and m2.user_id = m.user_id
                 );
$users_with_meta = get_users([
    'meta_key' => 'some_key',
    'fields' => ['ID'],
]);

$users_with_meta = [];

foreach($users_with_meta as $user)
    $users_with_meta[] = $user->ID;

$users_without_meta = get_users(['exclude' => $users_with_meta]);