求一SQL语句

WeiWY 2007-02-27 09:43:10
表A 有四列 id,C1,C2,其中ID为主键。
我想把如下两个查询结果合并到一起:
1.select top 10 * from A where C1=0 order by id desc

2.select * from A where C1=1

使用
select top 10 * from A where C1=0 order by id desc union select * from A where C1=1 语法通不过。
...全文
255 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
cxmcxm 2007-02-28
  • 打赏
  • 举报
回复
同意楼上
marco08 2007-02-28
  • 打赏
  • 举报
回复
--try


select * from A where C1=1
union
select top 10 * from A where C1=0 order by id desc
一者仁心 2007-02-28
  • 打赏
  • 举报
回复
select * from A where C1=1
union all
select * from (select top 10 * from A where C1=0 order by id desc) as B
union all
select * from A where C1=1

两种方法
zsl5305256 2007-02-27
  • 打赏
  • 举报
回复
select * from
(
select top 10 * from A where C1=0 order by id desc
) a
union select * from A where C1=1

34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧