Database - Mysql - Relationship between tables / INNER, LEFT, RIGHT JOIN

Asked

Viewed 62 times

-2

I am making a database using the Mysql Workbench and I am in need of a brief assistance. I have six entities in total. tb_people who are related to two other tb_clients and tb_adm entities (because the registered user may be a client or Adm). tb_clients is related to tb_schedule (because the client schedules the date of the consultation) and tb_adm is related to tb_employees and tb_services (because only Adm can register employees and services). I managed to get the name of the client and the date of the consultation however, I need to also take the service that he will do, the price he will pay and the name of the employee who will serve the customer. Here is an attachment to better view the code:

inserir a descrição da imagem aqui

  • Do not post code as image, read the Manual and how not to ask questions, the code should always be published as text to facilitate the operationalization of who will respond.

  • Each JOIN must have its own ON clause. Its ON clause is wrong.

1 answer

-1

It seems to me what you want is:

SELECT *    FROM tb_pessoas 
            INNER JOIN tb_clientes ON tb_pessoas.idpessoa = tb_clientes.idpessoa
            INNER JOIN tb_agendar ON tb_clientes.idcliente = tb_agendar.idcliente
            INNER JOIN tb_adm ON tb_pessoas.idpessoa = tb_adm.idpessoa
            INNER JOIN tb_funcionarios ON tb_adm.idadm = tb_funcionarios.idadm
            INNER JOIN tb_servicos ON tb_adm.idadm = tb_servicos.idadm;

Replace the * by the fields you wish, remembering to qualify them when necessary.

Browser other questions tagged

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