Unrolling an SQLite pivot query for a static ORM, the problem is that it needs nulls for missing values.
table student
student_id | name
1 "Fred"
2 "Tim"
PK(`student_id`)
table grade
student_id | data_id | grade
1 1 5.0
1 2 5.0
2 2 5.0
PK(`student_id`,`data_id`),
FK(student.studentid)
FK(data.data_id)
table data
data_id | description
1 "summer"
2 "autumn"
PK(`data_id`)
I need the results to include a null row for the static ORM to tablulate correctly. In my mind, that should mean a LEFT join:
SELECT * FROM student
join grade using (student_id)
LEFT OUTER JOIN data
ON grade.data_id = data.data_id
As Tim was absent for his summer exam, there is no row for student_id | data_id PK_pair(2,1) in table grade.
The query currently returns:
sID | name | dID | grade | description
"1" "Fred" "1" "5.0" "summer"
"1" "Fred" "2" "5.0" "autumn"
"2" "Tim" "2" "5.0" "autumn"
This row is missing in result:
sID | name | dID | grade | description
"2" "Tim" "1" null "summer"