I have a master table (Team) and a detail table (TeamMember). TeamMember has a FK to Team. I need to get the Team record for the team that has the most team members. I at first had
SELECT team.name
FROM team
INNER JOIN (SELECT TOP 1 COUNT(*) AS membercount,
teamID
FROM teammember
GROUP BY teamID
ORDER BY Count(*) DESC) AS team_with_most_members
ON team.id = team_with_most_members.teamID
我得知,我无法在我的问询中使用“TOP(1)”。 任何人都知道我如何能够不这样做?
感谢!
Team
ID, Name
TeamMember
ID, TeamID, UserID