I have 4 tables with the following relationships:
Products have N Variations
Sizes have N Variations
Colors have N Variations
Variations belongs to Products, Sizes and Colors
The structure of the tables looks like this:
Variation
id | product_id | size_id | color_id | quantity | barcode
-------------+---------+---------+------+----------------------+
1 | 1 | 1 | 1 | 10 | 100991001
Product
id | cod | description | price
-------------+---------+---------+------
1 | 160 | T-Shirt | 10.00
Color
id | cod | description
-------------+---------+-----
1 | 10 | Blue
Size
id | size
-------------+
1 | P
I need the following result:
Result
cod_produto | desc_produto | desc_cor | desc_tamanho | preco | quantidade | barcode
160 | T-Shirt | Blue | P | 10.00 | 10 | 100991001
But my query (below) is returning empty .
SELECT product.cod as cod_produto,
product.description as desc_produto,
color.description as desc_cor,
size.size as desc_tamanho,
product.price as preco,
variation.quantity as quantidade,
variation.barcode as cod_barras
FROM variation INNER JOIN
product ON product.id = variation.product_id
INNER JOIN size ON size.id = variation.size_id
INNER JOIN color ON color.id = variation.color_id
What is the best way to do this query and what would be the correct syntax for My SQL and Postgres?