Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql SQL查询,从一个表中选择不在另一个表中的行_Mysql_Join - Fatal编程技术网

Mysql SQL查询,从一个表中选择不在另一个表中的行

Mysql SQL查询,从一个表中选择不在另一个表中的行,mysql,join,Mysql,Join,注册和集团成员 Registration Table id name ------- 1 A 2 B 3 C 4 D group_members Table name Gid ------- A 01 B 01 C 02 我需要从注册表中获取姓名,这些姓名不是组成员表中的成员,Gid为02。 输出必须明显A、B和D。 但我不知道如何做到这一点。请帮助。谢谢尝试

注册集团成员

Registration Table
id  name  
-------                
1   A    
2   B    
3   C
4   D

group_members Table
name  Gid 
-------                
A   01    
B   01    
C   02
我需要从注册表中获取姓名,这些姓名不是组成员表中的成员,Gid为02。 输出必须明显A、B和D。 但我不知道如何做到这一点。请帮助。谢谢尝试以下方法:

SELECT t1.*
FROM Registration AS t1
LEFT JOIN Group_members AS t2 ON t1.name = t2.name AND t2.Gid = '02'
WHERE t2.name IS NULL 
这将过滤掉
group\u members
表中带有
Gid='02'
的所有匹配记录,请尝试以下操作:

SELECT t1.*
FROM Registration AS t1
LEFT JOIN Group_members AS t2 ON t1.name = t2.name AND t2.Gid = '02'
WHERE t2.name IS NULL 
这将过滤掉
group\u members
表中与
Gid='02'
匹配的所有记录,这应该可以工作

select name from
Registration reg where 
not exists 
(select null 
from group_members gm
where gm.name = reg.name
and gm.gid = '02')
这应该行得通

select name from
Registration reg where 
not exists 
(select null 
from group_members gm
where gm.name = reg.name
and gm.gid = '02')