relational - three tables relations SQL select -
i'm learning sql, appreciated.
i have 3 tables: league
, player
, team
league
,player
many many (as player can in more 1 league)team
,player
many many (as player can on team in multiple leagues)league
,team
1 many.
i have following table ids:
league.id ----. league_has_player (league_id, player_id) .------ player.id team.id ----. team_has_player (team_id, player_id) .----- player.id league ----. team.id (team.league_id)
i want players in league not on team in league.
here's broken attempt.
select * player p, join team t on t.league_id = l.id join league l on league.id = 2 p.id = league_has_player.player_id , not in (select team_has_player.player_id team_has_player)
i think you're trying more this. couple comments have pointed out, table schema isn't clear. impression attempt.
decalre @leagueid... select * player player.id in (select player_id league_has_player league_id = @leagueid) , player.id not in (select player_id team_has_player inner join team on team.id = team_has_player.team_id team.league_id = @leagueid)
Comments
Post a Comment