Reputation: 5695
I have a database with two tables, I want to get the total of rows in those tables with a single query. So far T tried:
SELECT (count(bill.*) + count(items.*)) as TTL FROM bill, items // Failed
SELECT count(*) as TTL FROM bill, items // wrong total
SELECT (count(bill.ID_B) + count(items.ID_I)) as TTL FROM bill, items // wrong total
SELECT count(bill.ID_B + items.ID_I) as TTL FROM bill, items // return the biggest total
Upvotes: 1
Views: 584
Reputation: 239311
Use two sub-queries:
select (select count(1) from bill) + (select count(1) from items);
Upvotes: 3