SQLite3 Simulate RIGHT OUTER JOIN with LEFT JOINs and UNION
Even though SQLite hasn't implemented RIGHT OUTER
or FULL OUTER
, it does have LEFT OUTER JOIN
, which should do what you'd like. Just have tbProjects
be on the left.
SELECT tbProjects.projectId, COALESCE(SUM(tbTasks.taskTime), 0) AS totalTime, tbProjects.projectName FROM tbProjects LEFT OUTER JOIN tbTasks ON tbProjects.projectId = tbTasks.projectIdGROUP BY tbProjects.projectId ORDER BY tbProjects.created DESC
You get NULLS
in totalTime
for projects that don't have any tasks, and the call to COALESCE()
replaces the null with a 0
.