首页 > 解决方案 > mysql选择带有后备的行

问题描述

我需要从表中获取一行,如果 store_id = 1 中有值则返回该行,否则返回该行 store_id = 0。

SELECT * 
FROM `catalog_category_entity_int` 
WHERE (store_id = 1 OR store_id = 0) 
AND attribute_id = 67

标签: mysqlmagento2

解决方案


使用限制

SELECT * 
FROM `catalog_category_entity_int` 
WHERE (store_id = 1 OR store_id = 0) 
AND attribute_id = 67
order by store_id desc limit 1

推荐阅读