I have two tables one to store a task and one to evaluate the task:
create table task(
_id integer primary key autoincrement,
task text not null);
create table eval (
_id integer primary key autoincrement,
taskid integer,
eval integer);
Some data:
INSERT INTO task VALUES (1,"A small job");
INSERT INTO task VALUES (2,"A easy job");
INSERT INTO eval VALUES (1,1,1);
INSERT INTO eval VALUES (2,1,2);
INSERT INTO eval VALUES (3,2,1);
INSERT INTO eval VALUES (4,2,2);
Then a view joining the two tables:
CREATE VIEW status AS
SELECT eval._id AS _id,
eval.taskid AS taskid,
eval.eval AS eval,
task.task
FROM task JOIN eval
ON task._id = eval.taskid;
SQLite Database Browser doesn’t support views. What’s a good database browser for android development on linux?
Secondly, consider this query: Select the highest evaluation on each task
SELECT s.task, s.eval
FROM status AS s
JOIN (
SELECT task, MAX(eval) AS maxeval
FROM status
GROUP BY task
) AS pm ON s.task = pm.task AND s.eval = pm.maxeval;
Resulting in:
s.task s.eval
A easy job 2
A small job 2
How do I implement this query in an Android app? I’ve tried to pack it into a Cursor android.database.sqlite.SQLiteDatabase.query method and its siblings without much luck.
Is there a way to just pass the SQL query as a string into the database and get a result set back?
you can use SQLiteManager a firefox add-onn. It is a visual
browser for sqlite database. I am using it and it is very nice.
If you want to learn sqlite syntax, you can use this tutorial.
db.execSQL(sqlCommand)fore update, write and deleteoperations. For read operations you can use
cursor =, where db isdb.rawQuery(sqlQuery, null);
SQLiteDatabase‘s object.