SQLite Forum

Approximate COUNT(*) using sqlite_stat4
If you're just interested in the equivalent of `SELECT COUNT(*) FROM table1` after `ANALYZE` was run, this should do the trick `select cast(substr(stat, 0, instr(stat, ' ')) as integer) as "COUNT(*)" from sqlite_stat1 where tbl = 'table1'  limit 1`

Looking a bit more into how `sqlite_stat4` and `sqlite_stat1` work, I'm beginning to think that they can't be used to approximate the count of any more sophisticated queries. 

I think it would still be helpful to have some PRAGMA that would automatically interpret such `COUNT(*)` expressions as the corresponding sqlite_stat1 lookup.