-1

Anyone knows a code in Sqlite that you say a value and it checks how many of those are in the column_x? Imagine you say value Johnny , and it checks how many Johnnys are in the column_names.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115

1 Answers1

2

Just pass your column value which you want to count that how many time it present...

public long getCount(String column_x_Value) {
            long count;
     SQLiteDatabase db = this.getWritableDatabase();
            Cursor c = db.rawQuery("SELECT * FROM " + TABLE_NAME + " WHERE " + column_x + "='" + column_x_Value+ "'", null);
//here column_x name of column and column_x_Value which is to be counted
           count = c.getCount();
            if (c != null && !c.isClosed())
            c.close();
            return count;
        }
Mohd Saquib
  • 580
  • 4
  • 14
  • 1
    Too much code. `SELECT Count(Name) FROM Names WHERE Name = 'Johnny'` would directly return the count, without any extra cursor operation. – Phantômaxx Jul 14 '17 at 12:46