Negative limit offset in mysql

I create a highly rated server, and one of the necessary functions allows me to extract high scores around the current rating of users. I currently have the following:

SELECT * FROM highscores 
WHERE score >= ( SELECT score FROM highscores WHERE userID = someID ) 
ORDER BY score, updated ASC 
LIMIT -9, 19

The only problem here is that the offset LIMIT parameter cannot be negative, otherwise I think this will work dandy. So, in conclusion, is there any trick / way to provide a negative bias for the LIMIT bias, or maybe the best way to do this completely?

+3
source share
1 answer

You can either do a real pain in a single-user butt request, or just do it:

(SELECT * FROM highscores 
WHERE score <= ( SELECT score FROM highscores WHERE userID = someID ) 
ORDER BY score, updated ASC 
LIMIT 9)
UNION
(SELECT * FROM highscores 
WHERE score = ( SELECT score FROM highscores WHERE userID = someID ))
UNION 
(SELECT * FROM highscores 
WHERE score >= ( SELECT score FROM highscores WHERE userID = someID ) 
ORDER BY score, updated ASC
LIMIT 9)

, , . , . , SELECT *, . , , * .

+7

Source: https://habr.com/ru/post/1778760/


All Articles