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.
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.
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,
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