如何使用一个查询获取数据库上的总行数

时间:2012-09-28 23:26:02

标签: sql sqlite rows

我有一个包含两个表的数据库,我想通过一个查询获得这些表中的总行数。 到目前为止,T尝试过:

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

1 个答案:

答案 0 :(得分:3)

使用两个子查询:

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