android - sqlite query using foreign keys -


help sqlite n00b out, please.

i have 2 tables

   "create table students (" +           "_id       integer primary key autoincrement," +           "studentname      text not null," +           "studentpic       blob," +           "comment          text);"; 

and

   "create table classes (" +            "_id              integer primary key autoincrement," +            "classname        text," +            "attend           integer," +            "late             integer," +            "dtime            text," +            "student          integer references students(_id) on                              update cascade);"; 

i want display list of students in particular class, classes table reference them student-id, how can construct query pull single cursor fields of 'classes' table use actual names 'students' table ?

many in advance

you can use rawquery method following sql code:

select classes._id, students.studentname, classes.classname, classes.attend, classes.late, classes.dtime students, classes students._id=classes.student 

in short, selecting 2 tables, join them, have specify how joined. part after select tells want output. shows tables involved (whether or not parts of tables shown in output). default, if give 2 tables, possible combinations of 1 row first table , 1 second created, need criteria in clause narrows down match rows students table corresponding row in classes table matching id. works whether or not there foreign key relationship defined.

if have additional criteria clause, can add using and. example:

where students._id=classes.student , classes.classname="underwater basket weaving" 

there's tutorial on overall process of setting , using databases in sqlite in android (much of seem understand) here.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -