sql - Formulating a query for people not in a relationship -


i have model users can play multiple games (many many), , each user can in 1 or many teams (many many). each team associated particular game.

i'd extract people not in particular team particular game e.g. not in team 2, , can play game 5

the model looks like...

player     id  player_game     player_id     game_id  game     game_id  team     id     game_id  team_player     team_id     player_id 

i've played around sql 1/2 day now, , not getting anywhere fast. appreciated.

using example have given, use following statement;

select      p.id ,   pg.game_id ,   tp.team_id  player p inner join     player_game pg     on p.id = pg.player_id inner join     team_player tp     on p.id = tp.player_id tp.team_id != 2 --!= donates not equal change team id strip out teams out of search , pg.game_id null --if player not in game value not set 

i have made couple of assumptions in regards model, if person not in game game id value null. if incorrect solution not work

the above statement return players team id not 2.

hope helps :)


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -