我要实现从6个不同的表中,取出每个表中最新的一条数据。以下用union all联合查询出来的结果时报:union出错、CREATE PROCEDURE   zuixin
AS
BEGIN
select  top 1  标题,本章更新时间  from  医学动态表  order by 本章更新时间 desc
union all
select  top 1   标题,发布时间 from 热点医讯表  order by 发布时间 desc
union all
select top 1 指南名称,本站更新时间 from 临床指南表  order by 本站更新时间 desc
union all
select  top 1图书名称,本站更新时间 from 医学书库表  order by 本站更新时间 desc
union all
select  top 1 杂志名称,文章发表时间 from 医学杂志表 order by 文章发表时间 desc
union all
select top 1  病例名称,本站更新时间 from 疑难病例表  order by 本站更新时间 desc
END
GO

解决方案 »

  1.   

    这是sql server的语法吧    这里是oracle板块!
      

  2.   

    select top 1 标题,本章更新时间 from 医学动态表 order by 本章更新时间 desc
    union all
    select top 1 标题,发布时间 from 热点医讯表 order by 发布时间 desc
    union all
    select top 1 指南名称,本站更新时间 from 临床指南表 order by 本站更新时间 desc
    union all
    select top 1图书名称,本站更新时间 from 医学书库表 order by 本站更新时间 desc
    union all
    select top 1 杂志名称,文章发表时间 from 医学杂志表 order by 文章发表时间 desc
    union all
    select top 1 病例名称,本站更新时间 from 疑难病例表 order by 本站更新时间 desc---主要原因要对一下,字段名的数据类型对不对
      

  3.   

    --还有union all,order by 只能是放在最后!
      

  4.   


    sql语句不是都差不多,我也知道这是oracle板块呀、
      

  5.   


    懂oracle的,sql server不懂说得过去吗?
      

  6.   


    数据类型都没问题啊,把union all去掉就可以执行了,不过不能联合查询出来呢,请问怎么该呢?
      

  7.   

    有些SQL Server支持的函数在Oracle是行不通的。
    同样,Oracle中也有函数在SQL Server的函数也是不能用的。
    所以,你这个问题很无语。
      

  8.   

    去表最新字段,oracle可以这样写。select orderno,creation_date
      from(  
    select to_char(order_number) as orderno,creation_date,sum(1) over(order by creation_date desc) as num
      from oe_order_headers_all
      )  
     where num=1 
    union all
    select segment1,creation_date
      from(
    select segment1,creation_date,sum(1) over(order by creation_date desc) as num
      from po_headers_all
      )
     where num=1