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
I was informed that I cannot use TOP(1) in my queries. Anyone have an idea how I can do it without?
Thanks!
Team
ID, Name
TeamMember
ID, TeamID, UserID
This one is crude but it works: