SELECT DISTINCT Colors.* FROM ( SELECT PSA.id as 'color_id', PSA.sort_order, PSAT.* FROM pri_store_attribute AS PSA INNER JOIN pri_store_attribute_text AS PSAT ON PSAT.id = PSA.id WHERE PSA.super_attribute_id = 1 AND PSAT.language_id = 'pt' ) AS Colors INNER JOIN ( SELECT DISTINCT PSP.*, PSPA.attribute_id as 'color_id' FROM pri_store_product AS PSP INNER JOIN pri_store_product_attribute AS PSPA ON PSPA.product_id = PSP.id INNER JOIN pri_store_product_attribute AS PSPA2 ON PSPA2.product_id = PSP.id INNER JOIN pri_store_product_attribute AS PSPA3 ON PSPA3.product_id = PSP.id INNER JOIN pri_store_product_category AS PC1 ON PSP.id = PC1.product_id INNER JOIN pri_store_product_category AS PC2 ON PSP.id = PC2.product_id WHERE PSP.status = 1 AND PC1.category_id IN (5) AND PSPA3.attribute_id IN (,) ) as Products ON Products.color_id = Colors.id ORDER BY Colors.sort_order ASC
Array