Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The concept of "below" for repeating scores is quite fuzzy: Think of 11 users having the same score, but you want the "10 below" a special row. That said, you can do something like (assuming you start with id=70)</p> <pre><code>SELECT score, username, id FROM scores WHERE score&lt;=(SELECT score FROM scores WHERE id=77) ORDER BY if(id=77,0,1), score DESC -- you might also want e.g. username LIMIT 5 -- you might want such a thing ; </code></pre> <p>Which will give you the rows in question inside this fuzzy factor, with the anchor row first.</p> <p><strong>Edit</strong></p> <p>Re-reading your question, you don't want the anchor row, so you need <code>WHERE score&lt;=(...) AND id&lt;&gt;77</code> and forget the first part of the <code>ORDER BY</code></p> <p><strong>Edit 2</strong></p> <p>After your update to the question, I understand you want only those rows, that have one of</p> <ul> <li>score &lt; score in anchor row</li> <li>score == score in anchor row AND name &lt; name in anchor row</li> <li>score == score in anchor row AND name == name in anchor row AND id &lt; id in anchor row</li> </ul> <p>We just have to put that into a query (again assuming your anchor row has id=70):</p> <pre><code>SELECT score, username, id FROM scores, ( SELECT @ascore:=score, @ausername:=username, @aid:=id FROM scores WHERE id=70 ) AS seed WHERE score&lt;@ascore OR (score=@ascore AND username&lt;@ausername) OR (score=@ascore AND username=@ausername AND id&lt;@aid) ORDER BY score DESC, username DESC, id DESC -- limit 5 //You might want that ; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload