
按某int型:select * from table order by id asc limit 10//如果是倒序就 order by id desc
按某字符串字段:select * from table order column+'' asc limit 10
在mysql中用limit,同样也可以查询第五条到第十条数据:select * from table order by id asc limit 5,10
相对SQL Server的top还要灵活。
mysql 没有top的用法。取而代之的是limit
语法为:limit m,n
省略n就可以得到你要的效果了。
select * from table1 limit 10
SELECT * FROM category LIMIT 3, 5
LIMIT 3, 5 这一句是关键3代表第几条数据之后开始,5代表差出几条结束(这里以mysql中的category表)
显示10条:
SELECT * FROM category LIMIT 0,10
或者
SELECT * FROM category LIMIT 10
SELECT * FROM 表 LIMIT 0, 3LIMIT 接受一个或两个数2113字参数。参数必须是5261一个整数常量。如果给定4102两个参数,第一1653个参数指定第一个返回记录行的偏移量,第二个参数指定返回记录行的最大数目。初始记录行的偏移量是 0(而不是 1)select scrname,stucount from scrtab
select top 3 scrname,stucount from scrtab order by stucount
先按人数排序,然后在查出前三个
sql server查询前n条记录:
因为id可能不是连续的,所以不能用取得10
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)