Search with Inner join [closed]

0

I'm doing a search where the user enters the order ID and the system does return the request's observation, product code and qtd. And these data are arranged in 2 tables. (I did not create the bank, it already came ready) However, with my query using innerjoin the console says the search is ambiguous. tb_ped_venda is where is the quantity and the id of the products tb_pedido_venda is where the order submissions are.

SELECT TB_PED_VENDA_ITEM.ID_IDENTIFICADOR,
TB_PED_VENDA_ITEM.QTD_ITEM,TB_PEDIDO_VENDA.OBSERVACAO 
FROM TB_PED_VENDA_ITEM INNER JOIN TB_PEDIDO_VENDA
ON TB_PED_VENDA_ITEM.ID_PEDIDO = TB_PEDIDO_VENDA.ID_PEDIDO
WHERE ID_PEDIDO=$id"
    
asked by anonymous 20.10.2017 / 20:26

2 answers

2

The database returns the ambiguous message when you have a field that is in more than one select table, in which case it is probably the REQUEST_ID of the where clause.

Try putting the table name up front:

where B_PED_VENDA_ITEM.ID_PEDIDO=$id
    
20.10.2017 / 20:30
4

The table has not been specified.

WHERE TB_PED_VENDA_ITEM.ID_PEDIDO=$id"
      ^^^^^^^^^^^^^^^^^

As ID_PEDIDO is a column in more than one of them, planner needs to know which one it refers to.

The fact that both are equal in their specific case is "mere coincidence". (Okay, it actually would have to be deduced programmatically, but it does not make sense to add this complexity in the query planner just so the programmer does not do the part of it).

    
20.10.2017 / 20:30