Question: I have the following tables 

```
      goal                    matches                 team_match

id | match_id | team_id | name     match_id      team_id | match_id | home_away
-----------------------------       -----        ------------------------------
1         1      1       Ronaldo       1             1         1        home
2         1      2       Messi                       2         1        away
3         1      2       Suarez                      2         1        away

```

Now I want to get just players who played in the away team.

```
SELECT DISTINCT g.name
FROM goal g

INNER JOIN matches m
ON g.match_id = m.match_id

INNER JOIN team_match tm
ON tm.match_id = m.match_id
AND tm.home_away = 'away'

WHERE m.match_id = '1' 

```

But instead of: 

```
 Messi
 Suarez 

```

I am getting:

```
 Ronaldo
 Messi
 Suarez 

```

It seams like my second INNER JOIN is totally ignored, even if I change from "home" to "away" I will get the same result.

Answer: 
The `INNER JOIN` is working correctly. Seems your database schema is the problem.

Why shouldn't `Ronaldo` be in the result set? You don't use the `team_id` anywhere. There is no information that `Ronaldo` was in the team that played `home` in the specified match.

---

A suggestion for a better schema:

```
Table teams
team_id
1
2

Table players:
playerid team_id name
1        1       Ronaldo
2        2       Messi
3        2       Suarez

Table matches
matchid hometeamid awayteamid
1       1          2

Table goals
matchid playerid
1       1
1       2
1       3

```

Then your query could look like this

```
SELECT p.Name FROM players p
INNER JOIN goals g ON (g.playerid = p.playerid)
INNER JOIN matches m ON (m.matchid = g.matchid AND m.awayteamid = p.team_id)
WHERE m.matchid = 1

```
You haven't proven that the first inner join is working either.
Try removing the blank lines