SQL: 随机从数据库取值

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

posted on 2013-04-17 11:42  水行者  阅读(216)  评论(0编辑  收藏  举报

导航