I have a query that requires what I think is a complicated JOIN. I have three tables that are sort of “children” of each other. The top table is “clan_members”. The next is “roster_members” which gets the clan_member id. The bottom one is “match_players” which gets the roster_members id. I wrote a loop that takes me through all of the results in the clan_members table. What I want to do is find out how many matches that clan member has played in. Here’s the layouts of the three tables:
[clan_members]
-id
- member_id
-join_date
[roster_members]
- id
- clan_member_id
- title
[match_players]
- id
- roster_member_id
- match_id
I have never done a JOIN with three different tables before and I have no idea what order to do them in. I would greatly appreciate it if someone could write me a query!
This query will get you the number of matches that clan member with id 123 has participated in:
On a side note, it would be good practice to name your columns consistently. For example, all columns that have the clan_member_id should be named the same. In the clan_members table its called id but in the roster_members table its called clan_member_id. Just makes it easier to understand how the tables join together.