使用一条sql查询多个表中的记录数

Posted 听歌敲代码

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用一条sql查询多个表中的记录数相关的知识,希望对你有一定的参考价值。

方法一:

 select t1.num1,t2.num2,t3.num3 from 
  (select count(*) num1 from table1) t1,
  (select count(*) num2 from table2) t2,
  (select count(*) num3 from table3) t3

方法二:

select sum(t.num1),sum(t.num2),sum(t.num3) from (
    select count(*) num1,0 as num2,0 as num3 from table1 
  union 
    select 0 as num1,count(*) num2,0 as num3 from table2
  union 
    select 0 as num1,0 as num2,count(*) num3 from table3
) t

 

以上是关于使用一条sql查询多个表中的记录数的主要内容,如果未能解决你的问题,请参考以下文章