The below function is in a javascript file. The intent is to return the maximum value in the rowid column of a sqlite database. Currently, it works only after a "Select * from table query" has been run. Why is this?
function lastRecord(){
db.transaction(function (tx) {
tx.executeSql('SELECT MAX(rowid) as mr FROM Surveys', [], function(tx, results){
var maxRowid = results.rows.item(0).mr;
alert(maxRowid);
});
});
}
I would appreciate clarification regarding what needs to be loaded to get SELECT MAX(rowid) to show the correct MAX rowid value every time the function is called. What is the standard format (structure) for implementing the MAX function? THANKS.
Have you tried using an order by and a limit? Something like
Select rowid as mr from surveys order by rowid desc limit 1
might work better for you.
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