A column has been specified more than once in the order by list. Columns in the order by list must be unique

Error Message:
Msg 169, Level 15, State 1, Line 1
A column has been specified more than once in the order by list. Columns in the order by list must be unique.

Severity level:
15.

Description:
This error message appears when a column name in the ORDER BY clause appears more than once.

Consequences:
The T-SQL statement can be parsed, but causes the error at runtime.

Resolution:
Error of the Severity Level 15 are generated by the user and can be fixed by the SQL Server user. Each column name in the ORDER BY clause can appear just once.

Versions:
All versions of SQL Server

Example(s):
SELECT *
  FROM Northwind.dbo.Orders
 ORDER BY OrderID, OrderID

Remarks:
In the above example the error is raised by the double specification of the OrderID column. This error message also appears when you don’t refer to the actual column name, but rather also when you reference the column by its ordinal position in the SELECT list. So, this SELECT also raises this error:

SELECT *, 1
  FROM Northwind.dbo.Orders
 ORDER BY OrderID, 1

The error is not raised when you give the column an alias in the SELECT list and refer to this alias instead in the ORDER BY clause. The following example does not raise this error:

SELECT *, OrderID AS t
  FROM Northwind.dbo.Orders
 ORDER BY OrderID, t




Related Articles :

  • No Related Articles Found

No comments yet... Be the first to leave a reply!

Software Reviews | Book Reviews | FAQs | Tips | Articles | Performance Tuning | Audit | BI | Clustering | Developer | Reporting | DBA | ASP.NET Ado | Views tips | | Developer FAQs | Replication Tips | OS Tips | Misc Tips | Index Tuning Tips | Hints Tips | High Availability Tips | Hardware Tips | ETL Tips | Components Tips | Configuration Tips | App Dev Tips | OLAP Tips | Admin Tips | Software Reviews | Error | Clustering FAQs | Performance Tuning FAQs | DBA FAQs |