sql-server – SQL Server 2012, error executing query

Question:

Good afternoon people

by running the query below:

select PRO_Descricao, PED_Numero
from pedido p, item i, produto pr
where p.PED_Numero = i.PED_Numero
and i.PRO_Codigo = pr.PRO_Codigo
and PRO_Descricao >= 'SA'
and pro_descricao < 'SB'

the following message appears in SQL server 2012:

Nome da coluna 'PED_Numero' ambíguo.

What is wrong?

Answer:

PED_Numero is a column that exists in pedido and in item .

To disambiguate, define table identifiers for the columns and tables involved:

select pr.PRO_Descricao, p.PED_Numero
from pedido p, item i, produto pr
where p.PED_Numero = i.PED_Numero
and i.PRO_Codigo = pr.PRO_Codigo
and pr.PRO_Descricao >= 'SA'
and pr.pro_descricao < 'SB'
Scroll to Top