How to select rows that start with specified letter in Flutter using Moor

166

All aspects of your questions beyond simple SQLite are beyond my knowledge.
But turns out (confirmed by OP) that my first doubt solved the problem:

Use 'R2%' instead of 'R2'. I.e. use the proper SQLite wildcard.

Share:
166
West
Author by

West

Updated on November 27, 2022

Comments

  • West
    West over 1 year

    I have a table called Items with a column called Name. How can I do a query to get only items that start with a certain letter?

    For example if I wanted all items that start with words R2. I tried the code below but its wrong :

     Future<List<Item>> getFilteredItems() => (select(items)..where((t) => t.Name.like('R2'))).get();
    

    What is the proper to write the query?

    • Yunnosch
      Yunnosch almost 3 years
      Did you try using SQLite wildcards as described for like? E.g. sqlitetutorial.net/sqlite-like => 'R2%'. If yes, what keeps you from using it?
    • West
      West almost 3 years
      @Yunnosch Oh yes I missed that. Thanks I've used wildcards and works now