Doubt with select in mysql

Asked

Viewed 72 times

0

Well I have the following tables:

Requests

id      id_cliente      id_vendador
1       10              20
2       10              30
3       10              20

Devotions

Id      data            id_pedido
1       2017/01/01      3

I need to make a ? select' informing the ? id' of the order table, and it has to return the returns that contain the same order customers.

Example:

and id IN(1,2)

He has to return the return ID 1 to me, because her 'id_request' is 3 and the 'id_client' is the same as the order.

Can anyone help me? I’ve broken my head here.

1 answer

1


You only need to make one INNER JOIN in the same table passing the field you want to link, in this case the id_cliente:

SELECT dev.id
  FROM pedidos ped
 INNER JOIN pedidos ped2 ON ped2.id_cliente = pd.id_cliente
 INNER JOIN devolucoes dev ON dev.id_pedido = ped2.id
 WHERE ped.id = [INSIRA AQUI O ID DO PEDIDO]
  • is giving this error here '#1241 - Operand should contain 1 column(s)'

  • @Hugoborges You have replaced what is between brackets with the id you want to put?

  • yes of course neh, put 'Ped.id = (1,2)'

  • @Hugoborges there is your mistake, the operator = accepts only one argument, to use the (1, 2) you must use the operator IN, as you yourself had said in your question: ped.id IN (1, 2)

  • 1

    off and even, my mistake. It worked, thank you very much

Browser other questions tagged

You are not signed in. Login or sign up in order to post.