Query that ranks students order by marks and give the position of student even when there are students with equal marks I need an sql that will rank students order by marks scored in a specific examtyp e.g CAT1 and give exact position even if the students have equal marks e.g in this sample data admNo 2525 and admNo 4093 scored equal marks in CAT1, so i need an sql that will fetch the positions as the same and skip give the next student number 3. the following sql that i tried does not consider a scenario like this.

$sql = "SELECT q1.rownum
FROM 
    (
        SELECT *, @rownum:=@rownum + 1 AS rownum
        FROM $table t, (SELECT @rownum:=0) r 
        WHERE examtyp =? AND termId=? AND year=? 
        ORDER BY points DESC
    ) q1
WHERE q1.admNo=$admNo"; 

resid  admNo streamIdexamtyptermIdmarks gradepointyear
1       2129    0   CAT1    1   525     C   62  2013
2       4093    0   CAT1    1   569     B+  69  2013
3       2129    0   CAT2    1   550     B+  67  2013
4       4093    0   CAT2    1   556     B+  68  2013
6       2129    0   FINAL   1   559     B+  68  2013
7       2129    0   AVERAGE 1   545     B   66  2013
7       4093    0   FINAL   1   581     B+  70  2013
8       4093    0   AVERAGE 1   569     B+  69  2013
9       2525    9   CAT1    1   569     B+  69  2013
SELECT t1.id, mark,
(SELECT COUNT(*) FROM marktable t2 WHERE t2.mark &gt; t1.mark) +1
AS rnk
FROM marktable t1 order by rnk;


SQLFIDDLE