首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

union附近有语法异常

2013-10-12 
union附近有语法错误sql我现在有6个表,表中有datetime属性的date,现在我想要的是选取每个表中的date最大的

union附近有语法错误
sql
我现在有6个表,表中有datetime属性的date,现在我想要的是选取每个表中的date最大的记录,并且把所有检索到的6条记录汇总并排序。

select sort,[name] from
(select * from
(select top 1 sort,[name],date as intro from Intro order by date desc)
union all
select * from
(select top 1 sort,[name],date as news from News order by date desc)
union all
select * from
(select top 1 sort,[name],date as teach from Teach order by date desc)
union all
select * from
(select top 1 sort,[name],date as inside from Inside order by date desc)
union all
select * from
(select top 1 sort,[name],date as outside from Outside order by date desc)
union all
select * from
(select top 1 sort,[name],date as help from Help order by date desc)
order by date)

提示union附近有语法错误,望指正!
sql union
[解决办法]
select?sort,[name]?from
????(??? select?*?from
????????(SELECT * FROM intro a
WHERE EXISTS (SELECT 1 FROM (SELECT MAX(date) date  FROM info ) b WHERE  a.date=b.date)
UNION ALL 
.....下面把表名改了就行)
????order?by?date)

热点排行