What is the problem with this query? Not unique table / alias

2

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)
    
asked by anonymous 24.09.2015 / 21:37

2 answers

2

The problem is that you are not actually using joins. Try this:

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 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)

After using alias before each select field as well.

    
24.09.2015 / 21:45
-2

Good morning, someone can give me a light

I have this query below:

SELECT bairro.ba_bairro AS ba_bairro, count(cadastro.ca_bairro) AS 
count_ca_outro_bairro, sum(cadastro.ca_bairro) AS sum_ca_bairro FROM 
(cadastro LEFT JOIN bairro ON bairro.ba_codigo=cadastro.ca_bairro) GROUP BY bairro.ba_bairro

And I make a mysql_fetch_assoc () showing the name of the neighborhood x and the total of its registration in the registration table.

Being that there is more than 10 fields called:

ca_outro_bairro_1,ca_outro_bairro_2,ca_outro_bairro_3,ca_outro_bairro_4,ca_outro_bairro_5,ca_outro_bairro_6,ca_outro_bairro_7,ca_outro_bairro_8,ca_outro_bairro_9,ca_outro_bairro_10

I wanted to add everyone because a register can live in the neighborhood x but has known in the neighborhood and.

I want to have a report that shows the total per neighborhood that adds the total of registrations in those columns listed above

Example: The neighborhood: "centro" neighborhood there is 20 register in the column ca_bairro and in the column ca_outro_bairro_1 has 10 register then in the neighborhood centro will show 30 register and thus with the other columns.     

30.08.2018 / 09:19