bsp; 3 rows in set (0.00 sec)
2.6.4 查询结果数量的限制
用LIMIT查看emp表中工资收入排名前两个员工的资料: mysql> select * from emp order by emp_sal desc limit 2;
查询结果显示如下: +--------+----------+---------+---------+------------+---------+ | emp_id | emp_name | emp_age | emp_sal | emp_bir | emp_sex | +--------+----------+---------+---------+------------+---------+ | 100001 | 红枫 | 29 | 9000 | 1977-01-01 | male | | 100002 | 丽鹃 | 27 | 8000 | 1979-12-31 | fmale | +--------+----------+---------+---------+------------+---------+ 2 rows in set (0.00 sec)
查看工资排名第2到第3的员工资料: mysql> select * from emp order by emp_sal desc limit 1,2;
查询结果显示如下: +--------+----------+---------+---------+------------+---------+ | emp_id | emp_name | emp_age | emp_sal | emp_bir | emp_sex | +--------+----------+---------+---------+------------+---------+ | 100002 | 丽鹃 | 27 | 8000 | 1979-12-31 | fmale | | 100005 | 啸天 | 27 | 4000 | 1979-07-10 | male | +--------+----------+---------+---------+------------+---------+ 2 rows in set (0.01 sec)
使用rand()抽样调查,随机抽取2个员工,查看其资料 mysql> select * from emp order by rand() limit 2;
如如下结果:(随机的)
+--------+----------+---------+---------+------------+---------+ | emp_id | emp_name | emp_age | emp_sal | emp_bir | emp_sex | +--------+----------+---------+---------+------------+---------+ | 100005 | 啸天 |   |