skip to Main Content

Im used to sql queries but im little confused how to get data from my database from one column. Here the example to get all items(include all columns):

 // Read all items (journals)
  static Future<List<Map<String, dynamic>>> getItems() async {
    final db = await SQLHelper.db();
    return db.query('items', orderBy: "id");
  }


In the database are few columns where one is named title. I did see something about rawQuery but i can not find any good examples of that, also i think that is not used much.

But what is the best way in the example above to get data from only the title column?

2

Answers


  1. return db.rawQuery("select title from items");

    Login or Signup to reply.
  2. No need to rawQuery to serve your task.
    You can follow the below process.

    await db.query('yourTableName', columns: ["yourDesiredColumn"]);

    Example based on your purpose.(Without rawQuery)

    await db.query('yourTableName', columns: ["title"]);

    Example based on your purpose.(With rawQuery)

    await db.rawQuery('SELECT title FROM yourTableName');

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