明天的明天 永远的永远 未知的一切 我与你一起承担 ??

是非成败转头空 青山依旧在 几度夕阳红 。。。
  博客园  :: 首页  :: 管理

SQL: 随机从数据库取值

Posted on 2012-03-02 13:58  且行且思  阅读(1043)  评论(0编辑  收藏  举报

 

select  ArticleId, Title,CreateDate from (SELECT top 2 *  FROM [Article] Where ArticleId <10 Order By NewId() ) AS A
UNION
select ArticleId,Title,CreateDate from  (SELECT top 8 * FROM [Article] Where ArticleId >10 Order By NewId() ) AS B

//**********************************************************************************************

 

select * from (SELECT top 2 *,NewId() As RandromX  FROM [Article] Where ArticleId < 100 Order By RandromX)  A 
UNION ALL
select * from (SELECT top 8 *,NewId() As RandromX FROM [Article] Where ArticleId > 200 Order By RandromX) B