Mwase
Mwase

Reputation: 1052

Is there a way or a work around to perform table joins in flutter using sqflite library?

Normally when I'm starting to code something I do some research on what technologies I'm gonna use. But when I started using sqflite library I didn't need to do so because it has such a high rating and use at flutter packages site.

So as I just did a thing or two with this library I'm at the point where I will need to perform table joins. Based on the information I've found out about this library it is say it currently doesn't support table joins. What I want Is to be able to perform table joins using sqflite, for now I don't care weather is a work around to achieve this task. I just need a clue so I can go with it and continue to code on this project I'm working on. Thank you, posted with Love.

Upvotes: 0

Views: 3322

Answers (3)

alextk
alextk

Reputation: 6239

it is say it currently doesn't support table joins

I'm not sure where you got this (wrong) information; sqflite supports whatever SQLite supports. JOINs are supported, maybe its syntax is specific/limited compared to MySQL or other SQL engine but you should be able to use any SQLite tutorial on SQLite and JOIN and use the rawQuery method:

In fact the JOIN keywords is not even necessary in SQLite, you can query on multiple tables and add a WHERE clause such as table1.id = table2.other_id.

SELECT album.title FROM album, artist WHERE album.artistId = artist.id

sqflite has not good documentation on that (it would imply re-documenting what https://sqlite.org does)

Upvotes: 1

ArmandoHackCode
ArmandoHackCode

Reputation: 389

You can use it in the following way, you can also concatenate external variables

  var res = await example.database.rawQuery(
      "SELECT data1,data2,table2_id,table3_id FROM table1 AS a , table2 AS b WHERE a.table2_id = ${table2Id.toString()} AND a.table3_id = b.id ORDER BY a.table2_id DESC");

Upvotes: 0

Mir Mahfuz
Mir Mahfuz

Reputation: 733

You can perform table joins with moor_flutter packages easily . Moor_flutter and here is a flutter moor blog link. You will find Joining the tables using moor flutter packages in this blog.

Upvotes: 0

Related Questions