Blog Archive

MySQL row_number() function display on result set

In MySQL there is no row_number() function. This following code worked for me.
set @i = 0; 
select 
    @i := @i+1 as myrow,
    customer_id,
    first_name,
    last_name,
    email,
    active
from
    sakila.customer;

MySQL row number function equivalent

-- OR --
select 
    @rownum := @rownum+1 as mySeq,
    customer_id,
    last_name,
    first_name,
    email,
    active
from
    sakila.customer c,
    (SELECT @rownum := 0) as r
order by last_name desc ,first_name desc
limit 0,10;

MySQL row_number() function display on result set

No comments :

Post a Comment