I am trying to join 3 tables to access data from each table. The main table in this case is going to be the Stats table. So I need to access the Players table to get their NextOpponent and then I need access to the Defense table to run calculations on the NextOpponent. Any ideas have to achieve all 3 of these.
Current SQL Statement: (Currently in an never ending loop of printing out duplicates)
$query="SELECT * FROM Stats
INNER JOIN Defense ON Stats.Team = Defense.Team
INNER JOIN Players ON Defense.Team = Players.team";
Here is my database structure.
Players
-PID (Primary)
-Name
-NextOpponent
Stats
-PID (Primary)
-Name
-Touchdowns
-Receptions
-etc....
Defense
-Team (Unique)
-Points
So my intended output would be:
Chris Johnson
Next Opponent: IND
Defense Points: 100
UPDATE: I can now access the fields, however when I echo the defense points it actually returns the points of the teams defense the player is on not their next opponents defensive points.
How about using
GROUP BY p.id?UPDATE
This was the final query:
SELECT * FROM Stats s JOIN Players p ON p.PID = s.PID JOIN Defense d ON d.Team = p.upcoming GROUP BY p.PID