导航
  • 主页
  • 基础类
  • 应用实例
  • 新技术前沿

[求助]如何写一句SQL,能查询联合语句结果中前10条的数据?

readings 2007-12-20 10:20:43
比如现在有一个UNION语句:

Select Title AS [Title] From OPENDATASOURCE ('SQLOLEDB','Data Source=(local);User ID=xxxxx;Password=xxxxx').Folkw_MinZuchannel.dbo.MinZu_Other
Where [Other_Title] Like '%河北%'
UNION
Select s_name AS [Title] From OPENDATASOURCE ('SQLOLEDB','Data Source=(local);User ID=xxxxx;Password=xxxxxx').feiyi.dbo.s_feiyi
Where [s_name] Like '%河北%'
Order By [Title] DESC

如何只查询结果中的前10条语句?
...全文
74 点赞 收藏 5
写回复
5 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
gagaxiaoyuer 2007-12-20
select top 10 from (condition)
回复
readings 2007-12-20
楼上各位,是不是哪里出错了?

错误信息如下:
服务器: 消息 1033,级别 15,状态 1,行 8
除非同时指定了 TOP,否则 ORDER BY 子句在视图、内嵌函数、派生表和子查询中无效。
回复
dobear_0922 2007-12-20
select top 10 * 
from
(
Select Title AS [Title] From OPENDATASOURCE ('SQLOLEDB','Data Source=(local);User ID=xxxxx;Password=xxxxx').Folkw_MinZuchannel.dbo.MinZu_Other
Where [Other_Title] Like '%河北%'
UNION
Select s_name AS [Title] From OPENDATASOURCE ('SQLOLEDB','Data Source=(local);User ID=xxxxx;Password=xxxxxx').feiyi.dbo.s_feiyi
Where [s_name] Like '%河北%'
Order By [Title] DESC
) T Order By [Title] DESC
回复
晓风残月0110 2007-12-20

select top 10 * from (
Select Title AS [Title] From OPENDATASOURCE ('SQLOLEDB','Data Source=(local);User ID=xxxxx;Password=xxxxx').Folkw_MinZuchannel.dbo.MinZu_Other
Where [Other_Title] Like '%河北%'
UNION
Select s_name AS [Title] From OPENDATASOURCE ('SQLOLEDB','Data Source=(local);User ID=xxxxx;Password=xxxxxx').feiyi.dbo.s_feiyi
Where [s_name] Like '%河北%'
Order By [Title] DESC
) t
回复
晓风残月0110 2007-12-20

select top 10 from (
Select Title AS [Title] From OPENDATASOURCE ('SQLOLEDB','Data Source=(local);User ID=xxxxx;Password=xxxxx').Folkw_MinZuchannel.dbo.MinZu_Other
Where [Other_Title] Like '%河北%'
UNION
Select s_name AS [Title] From OPENDATASOURCE ('SQLOLEDB','Data Source=(local);User ID=xxxxx;Password=xxxxxx').feiyi.dbo.s_feiyi
Where [s_name] Like '%河北%'
Order By [Title] DESC
) t
回复
发动态
发帖子
MS-SQL Server
创建于2007-09-28

3.2w+

社区成员

MS-SQL Server相关内容讨论专区
申请成为版主
社区公告
暂无公告