We have two tables in our application that both have a ShowOrder column.We are using NHibernate in our application and using HQL we join these two tables ordered by ShowOrder of first table and second table respectively. Here's a simplified version of my query :
SELECT pr.Id as Id,pr.Title as Title, pr.ShowOrder as ShowOrder
FROM Process pr
INNER JOIN ProcessGroup prg ON pr.GroupId=prg.Id
ORDER BY prg.ShowOrder,pr.ShowOrder
In general, our application is working without any problem.But we have an old application and a conversion routine to convert its database to our new application database.
Whenever we convert an old database to our new database An error will occur when the SQL server wants to execute the above query. The exception says: "A column has been specified more than once in the order by list"!!! If we select pr.ShowOrder without an alias everything is OK .It seems that if there's a ShowOrder alias in select list ,SQL server ignores table aliases and assumes that pr.ShowOrder and prg.ShowOrder are the same.