This is my query:
select dept_name, count(*) as student_number
from Student s join Department d
on s.dept_id=d.dept_id
group by dept_name
order by student_number desc, dept_name asc
UNION
select d.dept_name, 0 as student_number
from Department d left join Student s
on s.dept_id=d.dept_id
where student_id is NULL
Error:
You have an error in your SQL syntax; check the manual that corespond to your mysql server version for the right syntax to use near 'UNION' select d.dept_name, 0 as student_number from Department d left join Student s
I have 2 tables the first:
Column Name | Type |
---|---|
student_id | int |
student_name | varchar |
gender | varchar |
dept_id | int |
the second
Column Name | Type |
---|---|
dept_id | int |
dept_name | varchar |