Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Product data Subquery with fallback to default #11

Open
Genaker opened this issue Dec 1, 2024 · 0 comments
Open

Product data Subquery with fallback to default #11

Genaker opened this issue Dec 1, 2024 · 0 comments

Comments

@Genaker
Copy link
Owner

Genaker commented Dec 1, 2024

SELECT
p.entity_id,
p.sku,
(
SELECT COALESCE(v.value, gv.value)
FROM catalog_product_entity_varchar AS v
LEFT JOIN catalog_product_entity_varchar AS gv
ON gv.entity_id = v.entity_id
AND gv.attribute_id = 71
AND gv.store_id = 0
WHERE v.entity_id = p.entity_id
AND v.attribute_id = 71
AND v.store_id = 1
LIMIT 1
) AS name,
(
SELECT COALESCE(v.value, gv.value)
FROM catalog_product_entity_int AS v
LEFT JOIN catalog_product_entity_int AS gv
ON gv.entity_id = v.entity_id
AND gv.attribute_id = 93
AND gv.store_id = 0
WHERE v.entity_id = p.entity_id
AND v.attribute_id = 93
AND v.store_id = 1
LIMIT 1
) AS color,
(
SELECT COALESCE(v.value, gv.value)
FROM catalog_product_entity_decimal AS v
LEFT JOIN catalog_product_entity_decimal AS gv
ON gv.entity_id = v.entity_id
AND gv.attribute_id = 77
AND gv.store_id = 0
WHERE v.entity_id = p.entity_id
AND v.attribute_id = 77
AND v.store_id = 1
LIMIT 1
) AS price
FROM
catalog_product_entity AS p;

Without fallback

SELECT
p.entity_id,
p.sku,
(
SELECT value
FROM catalog_product_entity_varchar
WHERE entity_id = p.entity_id
AND attribute_id = 71
AND store_id = 1
LIMIT 1
) AS name,
(
SELECT value
FROM catalog_product_entity_int
WHERE entity_id = p.entity_id
AND attribute_id = 93
AND store_id = 1
LIMIT 1
) AS color,
(
SELECT value
FROM catalog_product_entity_decimal
WHERE entity_id = p.entity_id
AND attribute_id = 77
AND store_id = 1
LIMIT 1
) AS price
FROM
catalog_product_entity AS p;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant