I'm having difficulty using MySQL.
I've been asking here already, and I've done a lot of testing and progress in crafting a select for a ranking .
I have a "player" table that holds among other infos, nome_jogador
and pontuacao
. These two infos are necessary for me to create a query that returns me a ranking , being the current player of the app (always in the center except first or last place), above the players score immediately higher than the score of the chosen player, and below the players with the score immediately lower than his.
In the query I was able to do this, but if I have a table with 30 players, my query reveals the score of the current, and the highest and lowest player, ignoring the closest intermediaries, which are the ones I need .
My current query :
select nome_jogador,pontuacao
from jogador
where pontuacao > (select pontuacao from jogador where id_jogador='4') limit 2
union
select nome_jogador,pontuacao
from jogador
where pontuacao < (select pontuacao from jogador where id_jogador='4') limit 2
union
select nome_jogador,pontuacao
from jogador
where id_jogador='4' order by pontuacao desc;
I want to adjust this query to show the others closest to the current player above and below. not the tips of the table.
I'm asking for help