-
order by newid() 各种数据库随机查询的方法
网络 2014/9/1 10:47:47order by newid() 各种数据库随机查询的方法,需要的朋友可以参考一下
SQL Server:
Select TOP N * From TABLE Order By NewID() Select TOP N * From TABLE Order By NewID()
NewID()函数将创建一个 uniqueidentifier 类型的唯一值。上面的语句实现效果是从Table中随机读取N条记录。
Access:
Select TOP N * From TABLE Order By Rnd(ID) Select TOP N * From TABLE Order By Rnd(ID)
Rnd(ID) 其中的ID是自动编号字段,可以利用其他任何数值来完成,比如用姓名字段(UserName)
Select TOP N * From TABLE Order BY Rnd(Len(UserName)) Select TOP N * From TABLE Order BY Rnd(Len(UserName)) Select TOP N * From TABLE Order BY Rnd(Len(UserName))
MySql:
Select * From TABLE Order By Rand() Limit 10 Select * From TABLE Order By Rand() Limit 10 Select * From TABLE Order By Rand() Limit 10
postgreSQL:
select * from glxt022 order by random() limit 5 select * from glxt022 order by random() limit 5
阅读(836) 分享(0)
上一篇: [转]MyISAM InnoDB 区别
下一篇: PayPal要从Java迁移到Node.js