While executing the below query in Mysql I am getting multiple records.
SELECT *
FROM catalog_product_entity_int
WHERE attribute_id = 99
and row_id = 378050
+----------+--------------+----------+--------+-------+
| value_id | attribute_id | store_id | row_id | value |
+----------+--------------+----------+--------+-------+
| 12101931 | 99 | 0 | 378050 | 4 |
| 21858725 | 99 | 3 | 378050 | 1 |
| 21861516 | 99 | 4 | 378050 | 1 |
+----------+--------------+----------+--------+-------+
I need a query which will fetch value for store_id 3 and if store_id 3 is not present then the value of store_id 0.
2
Answers
Try this please
This would pick the value of store_id 3 first, if you have such a row in your selected rows.
Then it tries to get the value of store_id 0 and if that also fails the value is 0.
That last part you have to check, how you will detect that there is neither a store_id 3 or a store_id 0 in your selection.
The group by clause should be controlled. Eventually attribute_id could be better
Get the max store_id and join to source