Last answered:

03 Jul 2021

Posted on:

02 Jul 2021

1

Resolved: SQL section 15 last video

Why have we used min(dept_no) , as min() is an agg func usd over numerical values , and an employee is associated with one department only so why is min() required there ?

1 answers ( 1 marked as helpful)
Instructor
Posted on:

03 Jul 2021

2

Hi Janhavi!

Great to have you in the course and thanks for reaching out!

Your understanding of the use of the MIN() function is correct. The reason we apply it in this context is to ensure that MySQL will return an output where only one department number will be displayed/associated per individual.
In other words, an employee may have worked in several department numbers throughout the years and best practices dictate we don't want to leave it to the SQL Optimizer to decide which of the department numbers will be displayed in the output. Instead, we can use the MIN() function to "navigate" the result towards the smallest department number.

Hope this helps.
Best,
Martin

Submit an answer