About my tables, I am creating a script for a game I like to play, if people has XYZ statement assigned to their account. Its based on 4 tables. 1 table with the past games saved with a match ID, then the next table holds match ID to player ID relation, table 3 then hold the player ID with the in-game ID whereas the last table holds info about what statement is assigned to them.
There can be up 15 players in 1 match, hence the relation tables, some players are seen more than once in different matches.
So the tables look like this: games (match ID) -> match to player (match ID to player ID) -> players (Player ID to In-game ID) -> player Info (In-game ID -> info needed to query)
So when the script is queried, I have the match owner UID which is saved with the match data in the first table with match information, it would return all the match IDs based on that owner ID, so all the match IDs then checks the next table to get all the unique player IDs, with that list then query next table to get a list of all those in-game IDs, with that list then query the last table to get each players in-game assignments.
I cant change the way the tables are, since all other scripts are depending on those.
I have tried some join statements, but none gotten what I needed and none even half what I wanted, but I do think its the usage of joins that will get me to where I need to be.
I am trying to get a list from the last table on the picture based on the ID from the first table. I know I need to use joins, however I am not sure how to in what order, some guideline is needed as to how I organize the joins to get the data I need.
This is the query I have so far, its semi working since it does return a list of the needed info, but there is way more than there should be, so somehow its selecting something it shouldn’t, the thing is I dont know how many total it should return, thats one of the thing I am gonna need the query for, to get a total count of it. But I do know it returns to many, as there is a total of 1355 banned players from the database in total, but this query returns 2254 rows, so somehow selected why more than it should.
SELECT b.*
FROM banInfo AS b
JOIN players AS p ON b.game_id=p.game_id
JOIN player2match AS pm ON pm.pid=p.id
JOIN matches AS m ON m.id=pm.mid
JOIN users AS u ON u.id=m.uid
WHERE u.id = 1 AND b.comBan = 1 OR b.playerBan > 0 OR b.nGameBan > 0
Thanks!