0

Have a sql request:

SELECT
`e` .*,
`cat_index`.`position` AS `cat_index_position`,
`price_index`.`price`,
`price_index`.`tax_class_id`,
`price_index`.`final_price`,
IF(price_index.tier_price IS NOT NULL,
LEAST(price_index.min_price, price_index.tier_price),
price_index.min_price) AS `minimal_price`,
`price_index`.`min_price`,
`price_index`.`max_price`,
`price_index`.`tier_price`
FROM
`catalog_product_entity` AS `e`
INNER JOIN `catalog_category_product_index_store2` AS `cat_index` ON
cat_index.product_id = e.entity_id
AND cat_index.store_id = '2'
AND cat_index.visibility IN(2,4)
AND cat_index.category_id = '153'
INNER JOIN `catalog_product_index_price` AS `price_index` ON
price_index.entity_id = e.entity_id
AND price_index.website_id = '3'
AND price_index.customer_group_id = '1'
WHERE
((`e`.`sku` IN('96005', '5806', '96004','PROD91','PROD187')))
    AND (e.created_in <= '1548056609')
    AND (e.updated_in > '1548056609')

And I get this result:

enter image description here

But I need to get it in order like inside IN: 96005','5806','96004', 'PROD91','PROD187'

4
  • Add line breaks, please. Commented Sep 23, 2019 at 12:19
  • 1
    What is the logic behind the target odering? Commented Sep 23, 2019 at 12:22
  • I need the same order as inside IN expression Commented Sep 23, 2019 at 12:24
  • Just add ORDER BY FIELD(e.sku, '96005', '5806', '96004','PROD91','PROD187') Commented Sep 23, 2019 at 12:33

1 Answer 1

0

use "case" statement ex:

SELECT * FROM 
...
ORDER BY case when <your_value> = '96005' then 1
          when <your_value> = '5806' then 2
          when <your_value> = '96004' then 3
          when <your_value> = 'PROD91' then 4
          when <your_value> = 'PROD187' then 5
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.