从表topic中随机查询topictype为1和2的记录各10条,

select * from
(
 select * from
 (
  select top 10 topicid,topic,topictype,content,answer,author,addtime,itemid from cean_topic where topictype=1 order by newid()
 ) as a1
  union  all
 
 select * from
 (
  select top 10 topicid,topic,topictype,content,answer,author,addtime,itemid from cean_topic where topictype=2 order by newid()
 ) as a2
 
) as a3

 

使用union all进行查询结果的合并,

SQL数据库用上面语句需要对子查询语句列出详细的列名,而Access则不需要,

posted on 2009-12-13 18:01  cean  阅读(457)  评论(0编辑  收藏  举报