INNER JOIN in 4 tables

Asked

Viewed 515 times

2

I have 4 tables:

TB_OS_MANUTENCAO: inserir a descrição da imagem aqui

TB_OS_ELETRONICA: inserir a descrição da imagem aqui

TB_OS_MECANICA: inserir a descrição da imagem aqui

E TB_OS_INFORMATICA: inserir a descrição da imagem aqui

as shown in the images, all tables have a common field, calledid_, and also with a common value, 8. This field is not marked as UNIQUE or another type, it is a normal tinyint field. The problem is that I am not able to come up with any SQL command with INNER JOINS that captures ALL (*) the data of the 4 tables where this id_called (8) is equal.

2 answers

2


SELECT * FROM TB_OS_MANUTENCAO ma
INNER JOIN TB_OS_ELETRONICA el ON el.id_chamado = ma.id_chamado
INNER JOIN TB_OS_MECANICA me ON me.id_chamado = el.id_chamado
INNER JOIN TB_OS_INFORMATICA if ON if.id_chamado = me.id_chamado
WHERE me.id_chamado = 8

Or

SELECT * FROM TB_OS_MANUTENCAO ma,TB_OS_ELETRONICA el,TB_OS_MECANICA me,TB_OS_INFORMATICA if
WHERE el.id_chamado = ma.id_chamado
  AND me.id_chamado = el.id_chamado
  AND if.id_chamado = me.id_chamado
  AND me.id_chamado = 8
  • Thank you very much!

  • Hey, buddy. Another quick fix.. your query worked, but when I query it returns this message: "Current Selection does not contain a Unique column. Grid Edit, checkbox, Edit, Copy and Delete Features are not available" and the data returns all together, one next to the other, without skipping line. In the solution just I mark the id_called field as Unique ?

0

Come on,

If your database is Mysql, follow these tips.

If you are using "phpMyAdmin" version earlier than 4.6.0, upgrade to the latest, but if I were you I would install "Mysql Workbench CE"

  • You can edit your answer, no need to create another to complement ;)

Browser other questions tagged

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