ExamVeda
Login
Home
This question belongs to MySQL MySQL Miscellaneous
MySQL Miscellaneous
?

What is the significance of the statement "GROUP BY d.name" in the following MySQL statement?
SELECT d.name, COUNT (emp_id) emp_no
FROM department d INNER JOIN Employee e
ON d.dept_id=e.emp_id
GROUP BY d.name

Answer & Solution
Correct Answer: Option B
This SQL statement is designed to count the number of employees in each department. The key part you are asking about is "GROUP BY d.name".
Here's how it works:
1. `SELECT d.name, COUNT (emp_id) emp_no`: This part chooses the department name (`d.name`) and counts the number of employees (`COUNT (emp_id)`) in each department.
2. `FROM department d INNER JOIN Employee e ON d.dept_id=e.emp_id`: This joins the `department` and `Employee` tables based on the common field `dept_id`.
3. `GROUP BY d.name`: This is where the magic happens! It groups the results based on the department name (`d.name`). For each unique department name, the `COUNT(emp_id)` function counts all the employees associated with that department.
So, the correct answer is Option B:
"Aggregation of the field 'name' of table 'department'".
It means that the data is grouped by the department names, allowing you to count the employees within each specific department.
Examveda
Question posted by Examveda
Community

Join the Discussion

No comments yet Be the first to discuss this question.