连接表中的MySql

连接表中的MySql,mysql,sql,join,left-join,where-clause,Mysql,Sql,Join,Left Join,Where Clause,第一个表有几个字段,但“PersonId”是唯一感兴趣的字段。 第二个表有“PersEmId”和“PersEmGr” mysql是: select a.PersonId, b.PersEmId, b.PersEmGR from PersonRepDb a left join PersEm b on a.PersonId = b.PersEmId (conditions to be figured out) 在没有条件的情况下,输出为: 1

第一个表有几个字段,但“PersonId”是唯一感兴趣的字段。 第二个表有“PersEmId”和“PersEmGr”

mysql是:

   select  a.PersonId, b.PersEmId, b.PersEmGR
       from PersonRepDb a left join PersEm b 
       on a.PersonId = b.PersEmId
    (conditions to be figured out)    
在没有条件的情况下,输出为:

1   ABBOT.LE00  ABBOT.LE00  betty  
2   ABBOT.LE00  ABBOT.LE00  flutes  
3   ACKERBRO00      
所以我们看到ABBOT.LE分为两组“贝蒂”和“长笛”,而ACKERBR000不在任何组中

如果条件为:其中PersEmGr='sleets',则查询只返回ABBOT.LE00,这是正确的

然而,我想知道谁不在《长笛》中。如果条件为

where PersEmGr != 'flutes' OR PersEmGr  IS NULL
查询返回

1   ABBOT.LE00  ABBOT.LE00  betty <br>
2   ACKERBRO00      
1 ABBOT.LE00 ABBOT.LE00 betty
2 ACKERBRO00
ABBOT.LE00出现在这里,因为虽然他在《长笛》中,但他也在《贝蒂》中,这部电影充满了!='长笛的一部分条件


有谁能建议一种写条件的方法,这样查询就能找到所有不在长笛乐队的人,不管他们是否在另一组

将条件放入
ON
子句中

select  a.PersonId, b.PersEmId, b.PersEmGR
from PersonRepDb a 
left join PersEm b on a.PersonId = b.PersEmId AND b.PersEmGR = 'flutes'
WHERE b.PersEmId IS NULL

我喜欢它。从来没有想到过这一点。