Let's say there are two tables,

Table 1:
course_ID
1
2
...

Table 2:
class_ID........student_ID............course_ID
......1.................1......................... .2
......1.................2......................... .1
......1.................3......................... .2
......1.................4......................... .1

My code as follow:
Qt Code:
  1. courseModel=new QSqlQueryModel();
  2. courseModel->setQuery("SELECT *FROM Table1 WHERE course_ID IN (SELECT course_ID FROM Table2 WHERE class_ID=1)");
  3. ui->courseModelView->setmodel(courseModel);
  4. ui->courseModelView->show();
To copy to clipboard, switch view to plain text mode 

result is :

course_ID
1
2

what i want is without sorting and union:

course_ID
2
1
2
1

second question is that since i use sqlite3 as database, table is column head (horizontal), but i want show it vertical as:

course_ID 2 1 2 1

in QTableView

Any solution or ideas? Thank you in advance!