SQLite – Get Rows with Common Entry in Second Column

androidsqlite

I am working on an Android studios project and I have a table that has two columns item and listname.

enter image description here

I want to get all the items that have a common Listname so in this case if I were looking for items that have Market as a listname I only want to get the last 4 from the table, I only want to return the items. I have this but it keeps crashing.

   public Cursor getItem(String listname) {
    SQLiteDatabase db = this.getWritableDatabase();

    String selectQuery = "SELECT  * FROM " + LIST_ITEM_TABLE + " WHERE "
            + ItemListName + " = " + listname;

    Cursor c = db.rawQuery(selectQuery, null);
    
    return c;
}

Best Answer

String have to be in single quotes

Also i don't see ItemListName be filled, i hoe there is Listname in it

See like:

String selectQuery = "SELECT  * FROM " + LIST_ITEM_TABLE + " WHERE "
        + ItemListName + " like  '" + listname +"'";