MySQL中的ROWNUM的实现
MySQL 几乎模拟了 Oracle,SQL
Server等商业数据库的大部分功能,函数。但很可惜,到目前的版本(5.1.33)为止,仍没有实现ROWNUM这个功能。
下面介绍几种具体的实现方法.
建立实验环境如下
mysql> create
table tbl (
-> id int PRimary
key,
-> col int
-> );
Query OK, 0 rows affected (0.08
sec)
mysql> insert
into tbl values
-> (1,26),
-> (2,46),
-> (3,35),
-> (4,68),
-> (5,93),
-> (6,92);
Query OK, 6 rows affected (0.05
sec)
Records: 6 Duplicates: 0 Warnings:
0
mysql>
mysql> select * from tbl order by
col;
+----+------+
| id | col |
+----+------+
| 1 | 26 |
| 3 | 35 |
| 2 | 46 |
| 4 | 68 |
| 6 | 92 |
| 5 | 93 |
+