View Mysql Related Tables Query

Asked

Viewed 445 times

0

I have found some answers on the subject, but I still have some doubts, I will try to be as clear as possible. My Example of Banking. have the following tables

Table

  • Customer> id | name| request

  • system> id_client | id_system (foreign)

  • System > id | id_sist | version

  • Service > id_sist | id_num | id_serie (Foreign key)

  • Number > id | type | Lic

  • Serie > id | nserie | key

In the model above I have, the CLIENT with the key ID primary name and request(data) as follows the other tables, with the exception of cliente_system and Service, related to foreign.

What I’m asking is the following, in the customer’s registration he will have more than one service option, and in the service will have a type and type, I have a serial number, when performing the query bring all the service and series of the client within the table.

I have to use INNER JOIN for this rule.

I have the Database model in Mysql Workbench

I appreciate who can clear up my idea

  • What is your doubt?

  • You already answered your question, you will need to use joins, now you need to see the need/structure and formulate the query in a way that suits you.

1 answer

0


The JOINswould look like this:

SELECT * FROM cliente c
JOIN cliente_sistema cs ON cs.id_cliente = c.id
JOIN sistema st ON st.id = cd.id_sistema
JOIN servico sv ON sv.id_sist = st.id
JOIN numero n ON n.id = sv.id_num
JOIN serie sr ON sr.id = sv.id_serie;

Just put in the SELECT the fields you need.

Browser other questions tagged

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