How to avoid SQL Server error on ORDER BY with duplicate columns
问题 Although this question references PHP, it is not actually PHP-specific, so I have not flagged it as such. We have a PHP framework which supports multiple DB back-ends. There is a generic function in our data object class, which allows you to get records from the underlying table, with a specified criteria and sort order. It looks something like this: function GetAll($Criteria, $OrderBy = "") { ... // Add primary key (column 1) to end of order by list, // so that returned order is predictable.