Discussion Overview
The discussion revolves around the use of aliasing in SQL queries, specifically whether one can use an alias in the ORDER BY clause of a query in Microsoft SQL Server (MSSQL). Participants explore the implications of alias computation timing in relation to query execution.
Discussion Character
- Technical explanation
- Debate/contested
Main Points Raised
- One participant inquires whether it is possible to use an alias (e.g., 'x') in the ORDER BY clause instead of the original column name.
- Another participant asserts that it is indeed possible to use the alias in the ORDER BY clause, providing an example query that works with the Northwinds database.
- A different participant mentions having trouble downloading MSSQL2012 and suggests various workarounds for testing SQL queries, including using SQL Server 2014 or alternative database systems like MySQL.
- One participant reflects on the computation order of aliases, suggesting that aliases are computed after the query runs, while the ORDER BY clause is processed afterward, which may affect the ability to use aliases.
- Another participant notes rare instances where sorting on an alias did not work and mentions that they resolved such issues by ordering on the original expression instead.
Areas of Agreement / Disagreement
There is no clear consensus on the reliability of using aliases in the ORDER BY clause, as some participants provide examples supporting its use while others express uncertainty based on personal experiences with specific queries.
Contextual Notes
Participants discuss the internal workings of database engines regarding alias computation and ordering, but there are unresolved questions about the conditions under which alias sorting may fail.