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.
Ask
Anybody can ask a question
Answer
Anybody can answer
Vote
The best answers are voted up and moderated by our team

Solution explanation for UNION vs UNION ALL

Solution explanation for UNION vs UNION ALL

Super Learner
0
Votes
2
Answer

Hi, I do not quite get the solution given for the above-mentioned exercise. Can give detailed explanation? 

2 Answers

365 Team
0
Votes

Hi Ethan!
Thanks for reaching out.
Am I right to think that you are referring to the code that has been displayed here, please? https://365datascience.teachable.com/courses/360102/lectures/5529019
If yes, then can you please be more specific – what do you get? Do you obtain a different result or do you not manage to obtain a result set at the first place?
Finally, can you please share the query you executed before obtaining the different output?
The answers to these questions will help us understand what problem you are facing exactly. Alternatively, we might not be able to properly address the issue you are facing.
Looking forward to your answer.
Best,
Martin

Hi Martin, sorry I didn’t make it cleary beforehand. I didn’t encounter a different result. I just want to find out the meaning of the minus sign before subset A in the last row (ORDER BY -a.emp_no DESC)?

1 month

365 Team
0
Votes

Hi Ethan!
Thanks for your reply.
When you have the minus sign - it means that it reverses the order.
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 here: https://365datascience.teachable.com/courses/360102/lectures/5529019), 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.
Best,
Martin

×
EXTENDED SALE
Learn Data Science this Summer!
Get 50% OFF