sql - Select COUNT in two table in one query with MYSQL -


is there way can select count 2 table 1 single query.

at moment have following , doesn't work correctly.

select  count(t1.id) t1_amount, count(t2.id) t2_amount table1 t1, table2 t2 

here 1 way:

select (select count(*) table1) t1_amount,        (select count(*) table2) t2_amount 

here way:

select t1.t1_amount, t2.t2_amount (select count(*) t1_amount table1) t1 cross join      (select count(*) t2_amount table2) t2 

your method not work because , in from clause cross join. cartesian product between 2 tables.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -