Select CONCAT ( Name, ‘(‘ , LEFT(occupation,1) , ‘)’ )
FROM occupations
UNION
Select
CONCAT (‘There are a total of ‘, Count(Occupation) ,’ ‘, occupation, ‘s’ ) as line
FROM occupations
Group by occupation
ORDER by line
Why can I not use ‘line’ in Order by even though it is in Select statement and gets executed before. I can use it correctly without the UNION but once I use UNION statement it is not working and I also tried Order by Count(occupation) it did not work
2
Answers
Try using the ORDER BY and GROUP BY clause in outer query for UNION. e.g.
fiddle