Right. I think I found some explanation for this strange behavior.
IF you only do something like this
SELECT Column1, * FROM Table_Name
this should work fine.
But when you do something like
SELECT Column1, * FROM Table_Name ORDER BY Column1 --<-- this Column1 is contained in `*` as well as in the SELECT -- statement too, SQL Server needs to know which one to use -- in your order by clause.
It throws an error, because Column1 is twice SELECTED selected in SELECT Query, and SQL Server wants to know which column you want to order by your results.
The ambiguous column is in your Order by clause, but not in your Select statement.
Further explanation
Next, to prove your point, the following order of execution of SQL commands.
FROM clause
WHERE clause
GROUP BY clause
HAVING offer
SELECT clause
ORDER BY clause
As you can see, the SELECT statement is executed before the ORDER BY clause. so in your case, the SELECT clause will have two columns with the same name, and when it comes to ORDER BY, SQL Server results want to know which column to use in your ORDER BY, and it throws an Ambiguous column error.
When used with an alias, Ambiguity resolves and you get no more errors.
M.Ali source share