brgdotnet
asked on
Qualifying columns with table names in sql query
If I have a table named "Salary" with two columns named "Payment" and "Rank",
for the following select statement, why do I have to qualify the second parameter "Rank" in my select statement with the table name "Salary"
and I don't have to do that for the first parameter "Payment"
Here is the correct sql statement :
select Payment, Salary.Rank from Salary INNER JOIN Ranks ON Salary.Rank=Ranks.Rank
INNER JOIN Jobs ON Jobs.Title = Ranks.Title Where Jobs.Employee = 'Jim Baker'
And here is the incorrect sql statement which gives an error message of :
Msg 209, Level 16, State 1, Line 1
Ambiguous column name 'Rank'.
Note I know that we need the table name in front of the column "Rank", but Why do we not
need to do this for the parameter "Payment" ?
select Payment, Rank from Salary INNER JOIN Ranks ON Salary.Rank=Ranks.Rank
INNER JOIN Jobs ON Jobs.Title = Ranks.Title Where Jobs.Employee = 'Jim Baker'
for the following select statement, why do I have to qualify the second parameter "Rank" in my select statement with the table name "Salary"
and I don't have to do that for the first parameter "Payment"
Here is the correct sql statement :
select Payment, Salary.Rank from Salary INNER JOIN Ranks ON Salary.Rank=Ranks.Rank
INNER JOIN Jobs ON Jobs.Title = Ranks.Title Where Jobs.Employee = 'Jim Baker'
And here is the incorrect sql statement which gives an error message of :
Msg 209, Level 16, State 1, Line 1
Ambiguous column name 'Rank'.
Note I know that we need the table name in front of the column "Rank", but Why do we not
need to do this for the parameter "Payment" ?
select Payment, Rank from Salary INNER JOIN Ranks ON Salary.Rank=Ranks.Rank
INNER JOIN Jobs ON Jobs.Title = Ranks.Title Where Jobs.Employee = 'Jim Baker'
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.