Last answered:

16 Dec 2021

Posted on:

06 Nov 2021

0

using aliases in order by clause

Why didn't we use the following query after aliasing  e.emp_no as employee_id in the SELECT statement:

ORDER BY employee_id
GROUP BY employee_id  ??

I tried executing it this way but an error was thrown up.

3 answers ( 0 marked as helpful)
Posted on:

08 Nov 2021

0

Can you please provide the error message so that I can understand the situation?
I believe the issue might be coming from the position or the order of the queries. GROUP BY should be used before ORDER BY and you need to be careful with the parenthesis to ensure you are using the GROUP BY within the correct subquery.

Posted on:

28 Nov 2021

0

Hi Meenakashi
You must write the variables by their original names as they are stored in the database, not as we renamed them in order to run the query,

Instructor
Posted on:

16 Dec 2021

0

Hi Meenakshi and AbdElrahman!
Thanks for reaching out.

@: AbdElrahman
Thanks for sharing this piece of information with the Community!
@: Meenakshi
Yes, we can use in the ORDER BY and GROUP BY clauses this alias. The issue here is as AbdElrahman explained that the GROUP BY clause should be always before the ORDER BY clause. Could you please provide the whole code you’ve executed? This can help us assist you better. Thank you!

Looking forward to your answer.
Best,
Tsvetelin

Submit an answer