MySQL Query error using UNION/UNION ALL and Group By
I just tried on hackerrank and it works, You don't need to use Union.
select concat(name,'(',upper(substring(occupation,1,1)),')') from occupations
order by name;
select concat("There are a total of",' ',count(occupation),' ',lower(occupation),'s',".") from occupations
group by occupation
order by count(occupation) asc;
You forgot to use CONCAT
function to glue your selected data
Try something like this (also see this example on sqlfiddle):
(
SELECT CONCAT(NAME, '(', SUBSTRING(OCCUPATION, 1, 1), ')') as THETEXT, '1' as SELECTNUMBER
FROM OCCUPATIONS
)
UNION ALL
(
SELECT CONCAT('There are total ', COUNT(*),' ', OCCUPATION, (IF (COUNT(*) > 1, 's',''))) as THETEXT, '2' as SELECTNUMBER
FROM OCCUPATIONS GROUP BY OCCUPATION
)
ORDER BY SELECTNUMBER ASC, THETEXT ASC;