1
In a relational bank terminations have 1 contract, the contract has 1 real estate and two people(landlord and renter) how do I prepare the SELECT
to return these two people on the same line?
SELECT rescisoes.rescisao_id as id,
rescisoes.data_desocupaçao as desocupação,
contratos.controle as controle,
imoveis.logradouro as endereço,
pessoas.nome as locador,
pessoas.nome as locatário
FROM rescisoes
LEFT JOIN contratos ON contratos.contrato_id = rescisoes.contrato_id
LEFT JOIN imoveis ON imoveis.imovel_id = contratos.imovel_id
LEFT JOIN pessoas ON contratos.locador_pessoa_id = pessoas.pessoa_id
OR contratos.locatario_pessoa_id = pessoas.pessoa_id
thus returns two lines each with lessor and lessee with the same name.
Enter the table "people" two times one for the renter and the other for the lessor , will be two joins , give different aliases.
– Motta
https://forum.imasters.com.br/topic/557015-select-com-related-de-n-n/? do=findComment&comment=2222123
– Motta
I have already thought about this, however from the following error: #1066 - Table/alias 'people' not unique unless you have to do some more detail to work LEFT JOIN people ON contracts.renter_person=id people.personLEFT JOIN people ON contracts.locatario_pessoa_id = people.person_id
– Rodrigo A. Santos
LEFT JOIN people locatario ON contracts.locatario_pessoa_id = locatario . people_id LEFT JOIN people lessor ON contracts.personal renter_id = lessor.people_id using locator and lessor aliases to name the columns
– Motta
Thanks guy that’s it! if you can answer the question with this comment above for me to mark as final answer I thank you!
– Rodrigo A. Santos
SELECT termination.terminations_id as id, termination.data_vacate vacating, contracts.control as control, property.path the address, lessor.name the lessor, locatario.nome as locatário FROM rescisoes LEFT JOIN contratos ON contratos.contrato_id = rescisoes.contrato_id LEFT JOIN imoveis ON imoveis.imovel_id = contratos.imovel_id LEFT JOIN pessoas locador ON contratos.locador_pessoa_id = locador.pessoa_id LEFT JOIN pessoas locatario ON contracts.personal locatario_id = personal locatario_id
– Rodrigo A. Santos