I have the following query which returns some event details, the number of votes and a rank.
SELECT e.guid,
e.name,
(SELECT COUNT(ev.event_vote_id)
FROM event_vote sv
WHERE ev.event_uid = s.guid) AS votes,
@curRank := @curRank + 1 AS rank
FROM event e, (SELECT @curRank := 0) r
ORDER BY votes DESC
It returns the correct details including votes but the rank is broken.
Actual Result
guid | name | votes | rank
def test2 2 2
abc test1 1 1
ghi test3 0 3
jkl test4 0 4
Expected Result
guid | name | votes | rank
def test2 2 1
abc test1 1 2
ghi test3 0 3
jkl test4 0 4
For some reason test1 has a higher rank than test2.
I assume I need to use a JOIN but i'm unsure on the syntax.