sql >> Base de Datos >  >> RDS >> Mysql

seleccione un valor si existe, otro si no

Un enfoque es unir a la izquierda dos veces a catalog_product_entity_text. Una vez para ID 0 y otra para ID 3 y luego haz un COALESCE en tu selección

SELECT
..
 COALESCE(`short_description_id`.`value` , `short_description_id_DEFAULT`.`value`) AS `short_description`
..
FROM 
...

     LEFT JOIN `catalog_product_entity_text` AS `short_description_id` 
     ON p2c.product_id = short_description_id.entity_id 
         AND short_description_id.attribute_id = 62
         AND (short_description_id.store_id = 3)

     LEFT JOIN `catalog_product_entity_text` AS `short_description_id_DEFAULT` 
     ON p2c.product_id = short_description_id.entity_id 
         AND short_description_id.attribute_id = 62
         AND (short_description_id.store_id = 0)