I want to get the number of rows in each table in a Sqlite3 database. I want not to write a long request. I can get a list of tables as follows:
SELECT name FROM sqlite_master WHERE type='table'
and I would like to use it in a subquery, for example:
select count (*) from (SELECT name FROM sqlite_master WHERE type='table');
but just return the full lines in the subquery, which is not what I want.
How can I write a query that will list each table along with their calculations?
I have seen dynamic SQL for this kind of thing, but I don't think SQLite has this.
I wrote a bash loop for this, but I would prefer to do it as a single request
for t in $(sqlite3 data.db "SELECT name FROM sqlite_master WHERE type='table'"); do
echo -n "$t = "; sqlite3 data.db "SELECT COUNT(*) FROM $t;"
done
Ideas appreciated
source
share