What will happen when we fire below query?

Select ID,Name from Table_name order by 3;

 Posted by vishalneeraj-24503 on 7/2/2014 | Category: Sql Server Interview questions | Views: 453 | Points: 40
Answer:

It will give us error saying that:-
Msg 108, Level 16, State 1, Line 1
The ORDER BY position number 3 is out of range of the number of items in the select list.


Meaning that as we know that we can also access column by their's index position.So here Index 1 is Id column,index 2 is Name column but in order by clause we have passed 3 that is also an index position,but in select statement there are only 2 columns.That's why it will give an error.So to overcome this error,we have to pass number of column index as specified in select list.


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response