Last answered:

31 May 2024

Posted on:

29 May 2024

0

about MIN(de.dept_no) AS department_code

Hi,

I also checked the question done in the past but  I still didn't understand why you need to use the MIN for dept_no. I think it's because I really don't understand how this database is designed.


1.At first, I thought the output from MIN(de.dept_no) would be just 'd001' which is the smallst dept_no.

Could you correct my mistake and point out what I am missing here?


2.Does it mean in the database , the data is stored with same employee_ID but combined with different  dept_no because some employees had transfered to diffrent departments and we are going to extract the  department which the number is the smallest number ?


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

31 May 2024

2

Hi Osamu!
Thanks for reaching out.

1) We use it to extract just one department number. If we didn't, we would have obtained all of them, thus getting more records than we need. So, using MIN(de.dept_no) will return the smallest department number for each employee.

2) Yes, employees can have multiple department entries due to transfers, leading to multiple department numbers for the same emp_no. The query is designed to select the smallest department number for each employee, ensuring you get the first or primary department they were assigned to, according to your grouping and ordering logic. This approach helps in identifying the initial or primary department assignment of transferred employees.


Hope this helps.
Best,
Tsvetelin

Submit an answer