MySQL Database INNER Joins - Query Help
What I am trying to do is make a query so I can make the fights table more readable.
So Fighter 1 would pull the id of 1 from the fighters table, and Fighter 2 would do the same thing. Winner is either 0, 1, 2. Zero means it is a draw, and then 1 means that Fighter 1 won and 2 means that fighter 2 won.The query I tried so far:
SELECT 开发者_JAVA技巧CONCAT(first_name, ' ', last_name) 'Fighter 1',
CONCAT(victory_method.name, ' (', method_notes, ')') 'Victory'
FROM fights
JOIN fighters ON fights.fighter1_id = fighters.id
JOIN victory_method ON fights.victory_method_id = victory_method.id
Now that is a good start, but what I need is to figure out how to get Fighter 2 listed on there as well, and then also the Winner, either if it was a Draw or fighter 1 or 2 who won.
inner Join fighters table again, using alias as
SELECT
CONCAT(fo.first_name, ' ', fo.last_name, if (fights.winner=1, "Winner", "Loser")) 'Fighter 1',
CONCAT(ft.first_name, ' ', ft.last_name, if (fights.winner=2, "Winner", "Loser")) 'Fighter 2',
CONCAT(victory_method.name, ' (', method_notes, ')') 'Victory'
FROM fights
INNER JOIN fighters as fo ON fights.fighter1_id = fo.id
INNER JOIN fighters as ft ON fights.fighter2_id = ft.id
INNER JOIN victory_method ON fights.victory_method_id = victory_method.id
精彩评论