select count(*) from T1 union select count(*) from T2
我这样查却只能查到第一张表的记录数。

解决方案 »

  1.   

    select sum(cnt) cnt
    from
    (
      select count(*) cnt from T1 
      union all
      select count(*) cnt from T2 
    ) t
      

  2.   

    谢谢!如果是Sybase数据库呢?我这个原本在MSSQL上用的,但准备要迁移到Sybase上了。
      

  3.   

    select count(cnt) cnt 
    from 

      select 1 cnt from T1 
      union all 
      select 1 cnt from T2 
    ) t
      

  4.   


    你试一下吧,可能sql语句会通用的
      

  5.   


    select count(1)+(select count(1) from syscolumns) as Num from sysobjects aSybase 不知道,应该好写
      

  6.   

    谢谢两位!
    经测试,select count(1)+(select count(1) from syscolumns) as Num from sysobjects a
    是通用的。