Search code examples
androidsqliteandroid-sql

How to get all the items in sql using query based on a WHERE clause


I am new to database and I am trying to get all the data from table whose category column is equal to 1. This is my first attempt. Can someone please guide me where I am doing wrong?

public Cursor getAllFamilyMovies()
    {
        return database.query("movies", new String[] {"_id", "name"},
                "category=1", null, null, null, "name");
}

Solution

  • The "whereclause" and "whereargs" need to be separated as shown below:

    public Cursor getAllFamilyMovies() {
        return database.query("movies", new String[] {"_id", "name"}, "category = ?", new String[] {"1"}, null, null, "name");
    }