Your JOIN
will work only if the product has the same idQualityGate
in all three columns you have for it ( idQualityGate
, idQualityGate2
, idQualityGate3
).
It looks like you want a OR
, which will find records if at least one of the 3 fields exists in the Quality_Gate
table:
INNER JOIN qualitygate
ON qualitygate.idQualityGate = produto.idQualityGate1 OR
qualitygate.idQualityGate = produto.idQualityGate2 OR
qualitygate.idQualityGate = produto.idQualityGate3
This can also be written like this:
INNER JOIN qualitygate
ON qualitygate.idQualityGate IN (produto.idQualityGate1, produto.idQualityGate2, produto.idQualityGate3)
If you want to bring 3 quality gates per product, you need 3 JOINs:
SELECT * FROM produto
INNER JOIN familiaproduto
ON familiaproduto.idfamiliaproduto = produto.idNomeProduto
INNER JOIN qualitygate qualitygate1
ON qualitygate1.idQualityGate = produto.idQualityGate1
INNER JOIN qualitygate qualitygate2
ON qualitygate2.idQualityGate = produto.idQualityGate2
INNER JOIN qualitygate qualitygate3
ON qualitygate3.idQualityGate = produto.idQualityGate3
I would still recommend selecting only the required from each table, instead of getting everything with *
.