MySQL 使用RowNumber方式

Oracle及MS-SQL都有RowNumber的語法可用

MySQL則需要使用一些技巧

select x.id,x.val,x.seq, @i := @i + 1 as row_number 
from (
select 222 as seq,'row1' as id,'value1' as val from dual 
union all
select 111 as seq,'row2' as id,'value2' as val from dual 
) x,(select @i := 0) temp order by x.seq;

資料

QueryResult

加了Rownumber後

MySQL_RowNumber
如果只是要做分頁效果則使用

limit Start_Row,Page Of Row

limit 10,20

發表迴響