The name of column 'nroEmpleado' is ambiguous? SQLSERVER

1

I am doing the following query, however, it tells me that the name is ambiguous, I have read in several places and they mention that it is because I have 2 equal columns and the sql does not know which table I want to take the data from, but if you see in my query I put an alias to indicate which table I want to take the data, I hope your help.

this is my query ...

select p.nombres,c.unidad 
from tbl_contratos c 
INNER JOIN tbl_persona p 
ON p.nroEmpleado=c.nroEmpleado WHERE nroEmpleado ='50361'
    
asked by Sergio Cordova 20.10.2018 в 04:42
source

2 answers

0

Like @juan I tell you. When using aliases in tables, you must refer to the alias throughout the query.

select p.nombres,c.unidad 
from tbl_contratos c 
INNER JOIN tbl_persona p 
ON p.nroEmpleado=c.nroEmpleado WHERE c.nroEmpleado ='50361'

or

select p.nombres,c.unidad 
from tbl_contratos c 
INNER JOIN tbl_persona p 
ON p.nroEmpleado=c.nroEmpleado WHERE p.nroEmpleado ='50361'

depending on the case you need

    
answered by 20.10.2018 в 19:39
-1

You must use an alias in the where also

select p.nombres,c.unidad 
from tbl_contratos c 
INNER JOIN tbl_persona p 
ON p.nroEmpleado=c.nroEmpleado WHERE c.nroEmpleado ='50361'

where always use the column of the table that has an index if it exists but choose any.

    
answered by 20.10.2018 в 21:14