Select Mutiplos Mysql

Asked

Viewed 40 times

0

I need to search data from one table and complete with data from another table...

Main table: agendaphone Secondary table: neighborhood

principal: 
    [{"id":1,"tipo":"delivery","nome":"aaa","telefone":983585042,"endereco":"26 de outubro","logodouro":"av","numero":1965,"complemento":101,"bairro":"bela vista","senha":"dsadas","obs":"","pdtotal":0},{"id":2,"tipo":"delivery","nome":"aaa","telefone":999994242,"endereco":"26 de outubro","logodouro":"av","numero":1965,"complemento":101,"bairro":"horto","senha":"dsadas","obs":"","pdtotal":0}]


secundaria: 
    [{"id":1,"nome":"bela vista","valor":3},{"id":2,"nome":"horto","valor":6},{"id":3,"nome":"Centro","valor":1}]

would like to send the value field to the main table that corresponds to each neighborhood...

  • Because the id Neighborhood table repeats itself? It is not chave primária (PK)? If it is PK, then you need to record this id on the table agendatelefone as a chave estrangeira (FK). If it is not PK, you will be doing a relationship by name of the neighborhood and not by code, which is not recommended.

  • Dude malz e pq this not the correct answer was a little forged the ids are primary yes.. would be 1 2 3... to making by name the relation, I will edit...

  • give a look at the... password field it will lock him in the request and in the neighborhood to the customer... for now is not closed the code.. so I’m relating by name

1 answer

0

Solution

SELECT * FROM agendatelefone bro INNER JOIN bairro usr ON (bro.bairro = usr.nome)

Browser other questions tagged

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