Home  >  Q&A  >  body text

java - database query multiple tables

Prerequisite oralce, mybatis
Now there are multiple tables
I now need to count the amount of information in each table, that is, count(*)

My current method is to write multiple methods
For example, in mapper:
long selectCountA;
long selectCountB;
long selectCountC;

In this case, I have to check it three times in the database. Obtain 3 pieces of data respectively
I wonder if I can write a sql statement to directly obtain three values

Solution?

. Can you give me an oracle statement? It's all mysql. .

習慣沉默習慣沉默2712 days ago776

reply all(4)I'll reply

  • 巴扎黑

    巴扎黑2017-05-18 10:47:06

    select "a" name, count(1)
    from tableA
    union
    select "b" name, count(1)
    from tableB
    union
    select "C" name, count(1)
    from tableC
    

    Use multi-column writing method

    with 
    temp_a as (select count(*) num from talbeA),
    temp_b as (select count(*) num from tableB),
    temp_c as (select count(*) num from tableC)
    select temp_a.num, temp_b.num, temp_c.num from dual;

    reply
    0
  • PHPz

    PHPz2017-05-18 10:47:06

    select A.countA,B.countB from (select count(*) as countA from t_countA) as A ,(select count(*) as countB from t_countB) as B

    Like this?

    reply
    0
  • 过去多啦不再A梦

    过去多啦不再A梦2017-05-18 10:47:06

    Mysql

    Oracle
    Add from dual

    after the above statement

    reply
    0
  • 某草草

    某草草2017-05-18 10:47:06

    Mysql
    select table_rows from information_schema.TABLES where table_schema in ('schema1','schema2','scheman') and table_name in ('tableName1','tableName2','tableNameN')
    I believe oralce also has a similar system table

    reply
    0
  • Cancelreply