All pastes #249854 Raw Edit

Unnamed

public text v1 · immutable
#249854 ·published 2006-11-16 07:13 UTC
rendered paste body
here's table t:

winner_id | loser_id
----------+---------
1         | 2
1         | 2
1         | 3
2         | 1
2         | 3

select winner_id as id, count(*) as wins from t group by winner_id
gives me table x:

id | wins
---+-----
1  | 3
2  | 2

select loser_id as id, count(*) as loses from t group by loser_id
gives me table y:

id | loses
---+------
1  | 1
2  | 2
3  | 2

select id, wins, loses from x full outer join y on x.id=y.id
gives me table z:

id | wins | loses
---+------+------
1  | 3    | 1
2  | 2    | 2
3  | null | 2

except mysql 5 doesn't support outer join!  the above query with inner join would get me

id | wins | loses
---+------+------
1  | 3    | 1
2  | 2    | 2

and NOT include player with id=3 because he hasn't both won AND lost some games (he's only lost so far).