Welcome to the Tweaking4All community forums!
When participating, please keep the Forum Rules in mind!
Topics for particular software or systems: Start your topic link with the name of the application or system.
For example “MacOS X – Your question“, or “MS Word – Your Tip or Trick“.
Please note that switching to another language when reading a post will not bring you to the same post, in Dutch, as there is no translation for that post!
[Solved] SQLite - Use COUNT to count rows from multiple tables
(@hans)
Famed Member Admin
Joined: 12 years ago
Posts: 2859
Topic starter
April 28, 2016 10:22 AM
In regular SQL, you can count the number of rows in a table with
SELECT COUNT(*) FROM Table;
Now how would one do this with multiple tables?
Below an example by using subqueries, which is pretty obvious when you have worked with sub-queries before.
However, we cannot do a SELECT without a FROM followed by a table name.
Now since we do not really use the table in the FROM part, just type the name of Table1 and add a LIMIT 1 (otherwise you'd get as many rows back as Table1 has).
Note:
Make sure the table used in the FROM clause should have at least one record otherwise you'd get no results.
This can be ANY table, and doesn't even have to be related to the 2 tables used before the FROM clause.
SELECT (
SELECT COUNT(*)
FROM Table1
) AS Table1Count,
(
SELECT COUNT(*)
FROM Table2
) AS Table2Count
FROM Table1 LIMIT 1