SIFE
SIFE

Reputation: 5695

How to get the total rows on a database with one query

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

Answers (1)

user229044
user229044

Reputation: 239311

Use two sub-queries:

select (select count(1) from bill) + (select count(1) from items);

Upvotes: 3

Related Questions