I'm new to mysql but not new to sql. Below is my code and error message
Error: 42000][1064] You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'select content_type, count(*) as Red, 0 as Green from touchpoints ' at line 3
SELECT content_type, SUM(Red), SUM(Green)
FROM (
select content_type, count(*) as Red, 0 as Green
from touchpoints
where evaluatee_user_id = 6
and color_code = 'R'
group by content_type
UNION
select content_type, 0 as Red, count(*) as Green
from touchpoints
where evaluatee_user_id = 6
and color_code = 'G'
group by content_type
)
GROUP BY content_type
The subquery works and the output is:
M 1 0
SCI 5 0
SFA 3 0
SS 1 0
M 0 3