从表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则不需要,

相关文章:

  • 2021-07-20
  • 2021-10-02
  • 2021-11-30
  • 2022-12-23
  • 2022-12-23
  • 2021-09-16
  • 2021-12-31
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-08-09
  • 2021-07-11
  • 2020-07-15
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案