sql随机抽取数据库记录
Mysql:select * from [tablename] order by rand() limit 10
Sql Server:select top 5 * from [tablename] order by NEWID()
Access:select top 5 * from [tablename] order by rnd(id),其中id是自动编号的字段。在vb+access可以随机,但在asp里却没法得到随机的结果。可能是asp有缓存的结果吧,因此,需要修改一下这条语句,改为下面的方式:
randomize
select top 5 * from [tablename] order by rnd(-(id+rnd()))
Sql Server:select top 5 * from [tablename] order by NEWID()
Access:select top 5 * from [tablename] order by rnd(id),其中id是自动编号的字段。在vb+access可以随机,但在asp里却没法得到随机的结果。可能是asp有缓存的结果吧,因此,需要修改一下这条语句,改为下面的方式:
randomize
select top 5 * from [tablename] order by rnd(-(id+rnd()))
专注iOS、Golang开发。
技术博客:http://xiaopin.cnblogs.com