cbcp
cbcp

Reputation: 339

MySQL count across multiple tables and get single value

Imagine: t1 = 1 t2 = 3 t3 = 5

I need to run individual selects on each table, and report the count in a single amount, ie:

 select * 
   from (select count(*) from t1)
          + (select count(*) from t2)
          + (select count(*) from t3);

My end result should be = 9

Upvotes: 0

Views: 550

Answers (2)

Clodoaldo Neto
Clodoaldo Neto

Reputation: 125214

select 
    (select count(*) from t1)
    + (select count(*) from t2)
    + (select count(*) from t3);

Upvotes: 1

ruakh
ruakh

Reputation: 183251

You're pretty close; you can write:

 select (select count(*) from t1)
        + (select count(*) from t2)
        + (select count(*) from t3)
 ;

Upvotes: 3

Related Questions