如何获取未连接到其他记录的记录

How to get a record that isn't connected to other records

我有 1 个与许多 classes (1:N) 有关系的人(实体),我需要让所有没有 class 连接的人,使用 Sql 查询,我该怎么做?

这将return存在于persons中但没有记录在类中的所有personId:

select p.PersonId from Persons p where p.PersonId NOT IN (Select distinct c.PersonId from Classes c)
select p.* from Persons left outer join Classes C on p.personId = c.personId where c.classId Is Null

使用此查询获取没有 class 联系的人的列表。