如何从2个表里取出最大的一个编号?
其中一个是临时表,一个是一般的表。
编号是char类型的。

解决方案 »

  1.   

    select A.no from db1 A where A.no in (select max(no) from db1 where A.no=no);
    select B.no from db2 B where B.no in (select max(no) from db2 where B.no=no);
    然后再取两者中的最大者
      

  2.   

    select max(id)
    from
    (select id from table1
    union
    select id from temp_table_name)
      

  3.   

    select max(c.num) from (
    select max(编号) as num from 表1
    union
    select max(编号) as num from 表2
    ) c
      

  4.   

    declare @id1 char(10)
    declare @id2 char(10)
    select @id1=max(id) from tab1
    select @id2=max(id) from tab2if @id1>@id2 then
       @id1最大
    else
       @id2最大