Reputation: 459
I have the following relationship,
And wanted to know how I can get the team a game winner?
Upvotes: 0
Views: 67
Reputation: 4289
SELECT
m.id_match,
IF((id_home_team = ? AND score_home_team > score_away_team) OR
(id_away_team = ? AND score_home_team < score_away_team), 1, 0) AS won
FROM matches m
JOIN results r ON(r.id_match = m.id_match)
WHERE
id_home_team = ? OR id_away_team = ?
Replace the ?
with your team's ID.
In SQL Fiddle.
Upvotes: 1