Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Join tables in android [duplicate]

Tags:

android

sqlite

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.

like image 951
Siva Avatar asked Apr 18 '13 06:04

Siva


1 Answers

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"});
like image 149
Obl Tobl Avatar answered Oct 06 '22 00:10

Obl Tobl