Msg 169, Level 15, State 3 In SQL SERVER

Hello All, im trying to execute the below sql statement and i am getting the error.

Msg 169, Level 15, State 1, Line 1

A column has been specified more than once in the order by list .


SELECT TOP 1 customers.CustomerID as customerid,
               customers.CompanyName as companyname
 FROM customers INNER JOIN orders
            on customers.CustomerID = orders.CustomerID
 ORDER BY
            customers.CustomerID ASC,
            orders.CustomerID DESC

 

As the error message suggests, a column cannot be specified more than once in the ORDER BY list, specified either as the name of the column or as the non-negative

integer representation of the position of the column in the SELECT list.

Using the Select statement eariler. You need to remove the duplicate column Name

this message will be remove. So your query will be like this

SELECT TOP 1 customers.CustomerID as customerid,
           customers.CompanyName as companyname
 FROM customers INNER JOIN orders
     on customers.CustomerID = orders.CustomerID
 ORDER BY
     customers.CustomerID ASC

Hope you understand this. Also you can read this msdn link https://support.microsoft.com/en-us/kb/890771