Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

sqflite: How to make a SELECT with two columns inside the same rawQuery

I want to receive info from 2 columns with OR operator, but i can not visualice.

I have my column title and my column categoria. I want to make a select that affects both columns, something like this: selec * from title OR categoria where ...

this is what i have:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

final List<Map<String, dynamic>> queryResult = await db
    .rawQuery('SELECT * FROM todos WHERE title like ?', ['%'+queryCourse+'%']); //here i want to complete the select with both columns

>Solution :

Use the OR operator for the 2 columns:

final List<Map<String, dynamic>> queryResult = await db
    .rawQuery('SELECT * FROM todos WHERE title LIKE ? OR categoria LIKE ?', 
              ['%'+queryCourse+'%', '%'+queryCourse+'%']);

or:

final List<Map<String, dynamic>> queryResult = await db
    .rawQuery("SELECT * FROM todos WHERE title LIKE '%' || ? || '%' OR categoria LIKE '%' || ? || '%'", 
              [queryCourse, queryCourse]);

I assumed that for both columns you will use the same parameter queryCourse.
If not, then change the parameters with the ones you have.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading