🛠️ Scheduled Maintenance | We’ll be undergoing scheduled maintenance and upgrades between 00:00 PST Jan 26th until 00:00 PST Jan 28th. There may be brief interruption of services in that period. We apologize for the inconvenience.

The 365 Data Science team is proud to invite you to our own community forum. A very well built system to support your queries, questions and give the chance to show your knowledge and help others in their path of becoming Data Science specialists.
Anybody can ask a question
Anybody can answer
The best answers are voted up and moderated by our team

Union and Union all non-clearability

Union and Union all non-clearability


I didn’t understand the lecture on the union and union all operator in sql. I couldn’t find the reason behind the minus sign before a in the exercise.Please can you clarify it to me? 

1 Answer

365 Team

Hi Mark!
Thanks for reaching out.
1) ORDER BY a.emp_no DESC;
Ending the relevant query this way, you will obtain an output order with the highest employee number on top, the smallest employee number down the list, and the null values at the end.

2) ORDER BY a.emp_no ASC;
This ending will do the opposite – the null values will be on top, and then the employee numbers will grow from the smallest to the highest.

3) ORDER BY -a.emp_no DESC;
Using this code (and this is the one provided in the article, or Lecture 192), first orders the employees from smallest to highest number, and leaves 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.

Depending on the situation, you may choose between 1), 2), 3), and 4). In our example, we think 3) suits best; that’s why we ended the query with ORDER BY -a.emp_no DESC;
Hope this helps.