Example of COALESCE operator
Example: Give the total of marks for each exam (simplified solution)
SELECT CourseId,
COALESCE ((SELECT SUM (Mark)
FROM EXAM_MARK AS EM
WHERE EM.CourseId = C.CourseId ),
0) AS TotalMark
FROM COURSE AS C
Explanation
- The first operand to the invocation of COALESCE is a scalar subquery similar to Aggregate Operators. Recall the need to enclose the SELECT expression in parentheses, without which it would denote a table rather than a number.