In the above table, c
position is 3
.
Is there any function to find the position in Mysql?
update
In the above table, c
position is 3
.
Is there any function to find the position in Mysql?
update
try
select @rownum:=@rownum+1 ‘theposition’, t.* from mytable t, (SELECT @rownum:=0) r order by t.USER desc;
Use this:
SELECT x.user,
x.position,
x.number
FROM (SELECT t.user,
t.number,
@rownum := @rownum + 1 AS position
FROM TABLE t
JOIN (SELECT @rownum := 0) r
ORDER BY t.number DESC) x
WHERE x.user = 'c'
You can then get his position from x.position
I recommend you to add an id field. i don't know of any function to do that. you can select * and then in a script language search it or use a subquery. but i don't recommend that.
SELECT
@rowNumber := @rowNumber + 1 'RowNumber',
u.*
FROM Users u,
(SELECT @rowNumber := 0) r
ORDER BY u.User ASC