I wanna to retrieve column's names and rows count in a table in SQLite. Is it possible to do this is one command?
SELECT COUNT(*) FROM tablename
and
PRAGMA table_info(tablename))
The accepted answer was correct, but is now outdated, since SQLite 3.16.0 you can use PRAGMA functions
So you can now write:
SELECT * FROM pragma_table_info('tablename') JOIN (SELECT COUNT(*) FROM tablename);
Or if you really only need the name:
SELECT name, rowcount FROM pragma_table_info('tablename') JOIN (SELECT COUNT(*) AS rowcount FROM tablename);
(tested in SQLite 3.25.2)
Use it at your own risk though:
This feature is experimental and is subject to change. Further documentation will become available if and when the table-valued functions for PRAGMAs feature becomes officially supported.
A PRAGMA is a separate command, not a (sub)query, and cannot be combined with other SQL statements.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With