I have 3 tables in my sqllite database Two are config tables and one is main table where my data is stored. now how to retrive data from main table by joining 2 tables in android, How and where to perform join operations.
Can anyone guide me.
you can just execute a rawQuery.
For example something like this:
db.rawQuery("SELECT a.*
FROM table_1 a
INNER JOIN table_2 b ON a.id=b.anyId
INNER JOIN table_3 c ON b.id= c.anyId
WHERE c.key = ?", new String[]{"test"});
The first parameter is the query you want to execute. For all your keys you want to add to your query just add an ?
in the query.
The second parameter is a String Array. In this array you put your keys, like the example given above the value test
.
EDIT:
it's also possible to use rawQuery for update
, insert
or delete
.
For example one simple update query:
db.rawQuery("UPDATE table_1
SET fieldA = ?,
fieldB = ?
WHERE id = ?", new String[]{"test", "test2", "1"});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With