I'm still learning SQL, and my brain has a hard time dealing with it.
Let's say I have 3 tables:
teams players
and teams_players as my link table
All I want to do is run a query to get each team and players on them.
I tried this:
SELECT * FROM teams INNER JOIN teams_players ON teams.id = teams_players.team_id INNER JOIN players ON teams_players.player_id = players.id
But he returned a separate row for each player in each team. JOIN the right way to do this or should I do something else?
----------------------------------------- Edit
Okay, so from what I hear, this is not necessarily a bad way to do it. I just have to group the data by command while I execute my loop.
I have not tried modified SQL statements yet, but I will get back to you today.
To answer the question about the structure, I think I did not think about the returned row structure, which is part of what leads to my confusion. In this specific case, each team is limited to 4 players (or less), so I assume that the structure that is useful to me looks something like this:
teams.id, teams.name, players.id, players.name, players.id, players.name, players.id, players.name, players.id, players.name, 1 Team ABC 1 Jim 2 Bob 3 Ned 4 Roy 2 Team XYZ 2 Bob 3 Ned 5 Ralph 6 Tom