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)