I\'m trying to fetch the last inserted row Id of a Sqlite DB in my PHP application. I\'m using Zend Framework\'s PDO Sqlite adapter for database handling. the lastInsertId()
Do not use
SELECT * FROM tablename WHERE id = (SELECT COUNT(*) FROM tablename);
instead use
SELECT MAX(id) as id FROM tablename LIMIT 1;
or
SELECT id FROM tablename ORDER DESC LIMIT 1;