MySql select data from multiple tables - several sub records expected -


i have feeling might have got table structure wrong, appreciated.

i have, say, 3 tables

tbl_a (has class , section association)      id     classid     sectionid  tbl_b (has subject , class association)     id     classid     subjectid  tbl_c (has examination , class association)     id     classid     examid 

i need display records in following format

class | section (s) | subject (s) | examination (s) ---------------------------------------------------  grade 1 | a, b, c, d | english, maths, drawing... | assessment 1, assessment 2...  

sql script

select distinct t1.classid, t1.sectionid, t2.subjectid, t3.examid      `tbl_a` t1 join `tbl_b`  t2 on t1.classid = t2.classid join `tbl_c`  t3 on  t1.classid = t3.classid 

can above in achieve 1 sql query (with join etc) or need create separate sql recordsets loop through (for example, grade 1 have multiple subjects etc)

thanks heaps in advance!

select t1.classid,         group_concat(t1.sectionid order t1.sectionid),         group_concat(t2.subjectid order t1.sectionid),         group_concat(t3.examid order t1.sectionid)     `tbl_a` t1 join `tbl_b`  t2 on t1.classid = t2.classid join `tbl_c`  t3 on  t1.classid = t3.classid group t1.classid 

Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -