如何找到一个表中的哪些记录在另一个表中没有相应的记录 [英] How do I find which records in a table have no corresponding record in another table
问题描述
我的数据库中有两个表.一个叫人,一个叫团队.一个人可以在一个团队中. 如何检查以使用LINQ或sql来查找不在团队中的所有人员?
I have two table in my database. One called person and one called team. A person can be on one team. How do I check to find all the people in person that are not on a team using LINQ or sql??
推荐答案
您如何表示一个人与团队之间的联系.您是否亲自使用teamID字段?如果是这样,当一个人不在团队中时该怎么办?保持为空吗?
How do you represent the linkage of a person to a team. Do you use a teamID field in person? If so, what do you do when a person is not on a team? Keep it null?
select * from person where teamID is null
将其设置为-1吗?
select * from person where teamID == -1
也许您有一个person_team交叉表(这很奇怪,因为您说一个人只能在一个团队中).如果是这样
Maybe you have a person_team cross table (which would be odd because you said that a person could only be on one team). If so
SELECT * FROM person LEFT OUTER JOIN person_team
ON (person.id = person_team.personID)
WHERE person_team.personID IS NULL
或者,如果您还有其他问题,请告诉我们.
Or if you have something else -- tell us.
这篇关于如何找到一个表中的哪些记录在另一个表中没有相应的记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!