select max(maxvalue),id from
(
select max(date) maxvalue,id from table1
union all
select max(date) maxvalue,id from table2) as aano tested !

解决方案 »

  1.   

    1、select case when max(adate)>max(bdate) then max(aid) else max(bid) end from (select a.date adate,a.id aid,b.date bdate,b.id bid from test1 a,test3 b where a.id<>b.id)
    2、select case when max(adate)>max(bdate) then max(aid) else max(bid) end from (select a.date adate,a.id aid,b.date bdate,b.id bid from test1 a,test3 b where a.id=b.id)
      

  2.   

    zhaoyongzhu(zhaoyongzhu) 
    你是用两句来实现的,我想用一句,因为查出的条件还要嵌套到其他语句中
      

  3.   

    pandc2002 写得不是很好吗?你干嘛用别人的?
      

  4.   

    select max(dd),id from (select date dd,id from table1 union all select date dd,id from table2)
    这是我的方案,其中ALL去掉也可以,不过效率会底点,旁边没环境,没测过。
      

  5.   

    注意:
         pandc2002(pc)的思路不错哦,但是需要添加   group by id 
         zhaoyongzhu(zhaoyongzhu)写法中的 case when 在其他情况下会很有用的