What will happen if we execute below query?Will it compile or will it give the output?

Select created_date,* From Employee_Master e order by Emp_Id,Created_Date;

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

Above query will give us error as:-
Msg 209, Level 16, State 1, Line 1
Ambiguous column name 'Created_Date'.


Ambiguous column mean in above query we have specified created_date twice in select list and also provided alias name for table 'Employee_Master'.And also Table is searching for 2 Created_Date columns.That's why it's showing as Ambiguous column name.

So,to overcome this problem,we must specify alias name.column name as:-
Select e.created_date,* From Employee_Master e order by Emp_Id,e.Created_Date;

//OR
Select created_date,* From Employee_Master e order by Emp_Id,e.Created_Date;


Now,above query will work.


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response