0

I am writing a Javascript function where I need to count the number of unique entry in a certain column in my SQLite Database. So far, what I have tried to do is to just simply count the number of entries present as I need that as a parameter when I populate entries. My function goes as such:

MasterTreeDB.transaction(function(transaction) {
    transaction.executeSql("SELECT COUNT(*) FROM MasterTreeTable", [],
        function(transaction, result) {
            //console.log(result.rows);
            console.log(result.rows.item(0));
        },
        function(transaction, error){
            // error occured
            console.log("Error occured");

        }
    );
});

However, this is what the console shows: Object {COUNT(*): 4}

I have also looked around and I saw a solution that involved changing results.row.item(0) to results.row.item(0)["count(*)"]. However, when I did that, the log showed undefined

I feel like I'm really close to getting the result I want and I'm missing something rather basic. Any help/input is very much appreciated, thank you in advance.

1

1 Answer 1

1

"count the number of unique entry in a certain column in my SQLite Database":

select TheColumn from MasterTreeTable group by TheColumn;

Then result.rows.length is the number of unique values contained in TheColumn.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.