First row error with @rownum mysql -
i trying generate rownum mysql query. code.
select @rownum:=@rownum+1 rowno, (`plgap_nos`.`no_id` - 1) `no_id` `plgap_nos`, (select @rownum:=0) r limit 0, 10
while works fine, rownum of first row shoes 1621 , not 0.
it tried differnt code below. still same error persists.
select coalesce(@rownum:=@rownum+1,0) rank, (`cnxnifty_plgap_nos`.`no_id` - 1) `no_id` `money_database`.`cnxnifty_plgap_nos`, (select @rownum:=0) r limit 0, 10
it seems committing silly error not being able figure. can help.
additional info- how data looks-
rank no_id
1621 0
1 7
2 18
3 21
4 33
5 37
6 45
i want clear. following code exhibits same problem?
select (@rn := @rn + 1) rowno, (p.no_id - 1) no_id plgap_nos p cross join (select @rn := 0) params order p.no_id limit 0, 10;
the variable assignment in select
should executed after from
initialization. have not seen mysql initializations in wrong order (which 1 reason behavior seeing).
the changes made query (cross join
instead of comma, order by
, , table alias) should not affect result set. however, scoping semantics of cross join
different ,
, there small, small possibility cross join
might end fixing problem.
Comments
Post a Comment