I'm trying to select the top 3 entries from a table called games that has foreign keys to the players and 2 ints for individual scores for the host and opponent.
The Query:
SELECT
games.id, games.host_score, games.opponent_score, player.name
FROM games, player
WHERE player.id = games.host_player_id
|| player.id = games.opponent_player_id
ORDER BY games.host_score, games.opponent_score DESC LIMIT 3
The query completes but it comes back out of order:
id host_score opponent_score name
17 0 0 Temp2
17 0 0 Temp0
16 770 930 Temp0
When I run a query that doesn't have an OR it works. How can I get this method working?
Also is there a way to set a LIMIT of 50 but not count duplicates? For example if i wanted a limit of 2 but 3 people have the score 50 and 2 people have the score 20 it would return :
id host_score opponent_score name
17 50 0 Temp2
17 50 0 Temp0
17 50 0 Temp1
17 20 0 Temp3
17 20 0 Temp4
Or would it be better to run it as seperate quesies in php?