I came across a problem:
1066 - Not unique table / alias: 'catalog_product_entity_decimal'
SELECT DISTINCT catalog_product_entity.entity_id, sku, price as preco, qty as quantidade, stock_status as estoque, catalog_product_entity_decimal.value as embutido_regra_promo, catalog_product_entity_decimal.value as embutido FROM catalog_product_entity
INNER JOIN cataloginventory_stock_status ON (cataloginventory_stock_status.product_id = entity_id)
INNER JOIN catalog_product_index_price ON (catalog_product_index_price.entity_id = catalog_product_entity.entity_id)
INNER JOIN catalog_product_entity_decimal ON (catalog_product_entity_decimal.entity_id = catalog_product_entity.entity_id AND catalog_product_entity_decimal.attribute_id=249)
INNER JOIN catalog_product_entity_decimal ON (catalog_product_entity_decimal.entity_id = catalog_product_entity.entity_id AND catalog_product_entity_decimal.attribute_id=251)
The question is that the last two INNERS use the same table and column, but with different attributes in the select, one set to bring the attribute_id result 251 and the other 249.
Any solution?
RESOLUTION:
SELECT DISTINCT c0.entity_id, sku, price as preco, qty as quantidade, stock_status as estoque, c3.value as embutido_regra_promo, c4.value as embutido FROM catalog_product_entity c0 INNER JOIN cataloginventory_stock_status c1 ON (c1.product_id = c0.entity_id) INNER JOIN catalog_product_index_price c2 ON (c2.entity_id = c0.entity_id) INNER JOIN catalog_product_entity_decimal c3 ON (c3.entity_id = c0.entity_id AND c3.attribute_id=249) INNER JOIN catalog_product_entity_decimal c4 ON (c4.entity_id = c0.entity_id AND c4.attribute_id=251)