Last answered:

18 Jan 2023

Posted on:

14 Jan 2023

1

Resolved: Is the minus sign to keep null values of the emp_no at the bottom?

I tried to remove the minus sign and played with order ASC and DESC and realized that since we are ordering by emp_no if we used ASC normally we will have the records starting with NULL values and if we used DESC it will not give us the right order. so the minus sign is to have ascending order but starting with employee number that is NOT NULL and keep the null values at the bottom.

Is that correct?

3 answers ( 2 marked as helpful)
Instructor
Posted on:

16 Jan 2023

7

Hi Ashraf!
Thanks for reaching out.

The cases are:
1) ORDER BY a.emp_no DESC;
If you end the relevant query this way, you will obtain an output ordered with the highest employee number on top, the lowest employee number down the list, and the null values at the end.
2) ORDER BY a.emp_no ASC;
This ending of the query will do the opposite - the null values will be on top, and then the employee numbers will grow from the lowest to the highest.
3) ORDER BY -a.emp_no DESC;
Using this code, you will first order the employees from the lowest to the highest number, and then leave the null values at the end.
4) ORDER BY -a.emp_no ASC;
Following the logic explained so far, this ending would list the null value first, and will then order all employees from the highest to the lowest number.
So, you are right, if you ask for the 3) case.

Hope this helps.
Best,
Tsvetelin

Posted on:

17 Jan 2023

0

Thanks Tsvetelin, that was helpful

much appreciated
Ashraf

Instructor
Posted on:

18 Jan 2023

0

Hi Ashraf!
You are very welcome!

Best,
The 365 Team

Submit an answer