I am trying to get the top 5 opponents I played against.
The tables are as follow
USERS :
user_id name email
1 : Gait Bakker : user1@test.nl
2 : Freek ter Bekke : user2@test.nl
3 : Jan Zomer : user3@test.nl
4 : Mick Dundee : user4@test.nl
5 : Sjoerd Trekhaar : user@test.nl
GAMES :
game_id type training **created_by started_by **opponent_id won_by date
1 1 1 2 2 4 2 2015-08-10
2 1 1 5 2 2 5 2015-08-10
3 1 1 4 4 2 4 2015-08-10
3 1 1 2 3 3 3 2015-08-10
The problem is the fields with ** and that it needs to count the top 5 opponents.
I can be the game creator (created_by) and I can be the opponent_id (someone else started the game).
Still if I am the opponent I played against another player.
Edit Please use user-id = 2 for example.
As additional : Training needs to be 1 and won_by IS NOT NULL (needs to be filled in)
Result SQL Most played against opponent
user_id = 4, count = 2
user_id = 3, count = 1
user_id = 5, count = 1
So that means I played the most against user-id 4 and then user_id = 3 and user_id = 5