skip to Main Content

I am not sure how to go about it
I understood that I can use
"select * from" OR .where() function but I do not know how to implement it.

I have a third column in my database table that I intend to use to filter what is presented
any answers revolving this is greatly appreciated

any help is appreciate it cheers

2

Answers


  1. Please add some code, its hard to understand what you want to achieve. I’m just gonna give an example:

    Future<List<StudentModel>> checkStudentClass() async {
        final db = await instance.database;
    
        //SELECT * FROM tableNameHere WHERE columnNameHere = value AND columnNameHere = value
        final result = await db.rawQuery(
            "SELECT * FROM schoolDatabase WHERE class = 10 AND section = A");
    
        return result.map((e) => StudentModel.fromMap(e)).toList();
        //returns list of STUDENT studying in class 10th and section A
      }
    
    Login or Signup to reply.
  2. Yes you said i right, You can do with two ways adding condition directly in your sql query and fetching the according data:

      static Future<dynamic> _fetchDesiredData(
      {required String where,
      required String whereTerm,
      required String tableName}) async {
      /* Creating the raw query for fetching desired data. */
    
        dynamic desiredData = await _db.rawQuery(
          '''SELECT * FROM $tableName WHERE $where==$whereTerm;''');
    
        return desiredData;
      }
    

    here you need to pass the column name in where whose data you want to filter and the filter term in whereTerm and it will get your filtered data, You can play with it add more conditions if you want more advance filtration.

    Or you and fetch all the data and filter your list.

    List<CarDm> filteredList = carsDmList.where((ele) => ele.brand=='bmw');
    

    here you can add more condition will putting ||(or) &&(and) conditions.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search