我有1个人(实体)与许多类(1:N)有关系,我需要使用Sql查询让所有没有类的人连接到我,该怎么做呢?
答案 0 :(得分:0)
这将返回在person中存在但尚未在类中记录的所有personId:
select p.PersonId from Persons p where p.PersonId NOT IN (Select distinct c.PersonId from Classes c)
答案 1 :(得分:0)
select p.* from Persons left outer join Classes C on p.personId = c.personId where c.classId Is Null
使用此查询来获取没有上课的人的名单。