SELECT ARRAY_SORT( ARRAY_DISTINCT( ARRAY_FLATTEN( tag, 1 ) ) ) AS tags
LET tag = (
SELECT DISTINCT RAW tags
FROM `bucket`
WHERE `type` = 'product' AND tags IS NOT MISSING
AND active = true
ORDER BY LOWER(tags) ASC
)
SELECT DISTINCT RAW tag
FROM `bucket` AS b
UNNEST b.tags AS tag
WHERE b.`type` = 'product' AND b.tags IS NOT NULL
AND b.active = true
ORDER BY LOWER(tag)
SELECT
ARRAY_SORT( ARRAY_DISTINCT( ARRAY_FLATTEN( tag, 1 ) ) ) AS tags
LET
tag = (
SELECT DISTINCT RAW tag
FROM `bucket`AS b
UNNEST b.tags AS tag
WHERE b.`type` = 'product' AND b.tags IS NOT MISSING
AND b.active = true
ORDER BY LOWER(tag)
)
SELECT DISTINCT RAW tag
FROM `bucket`AS b
UNNEST b.tags AS tag
WHERE b.`type` = 'product' AND b.tags IS NOT MISSING
AND b.active = true
ORDER BY LOWER(tag)
This query should give results . Not sure why do u need ARRAY_FLATTEN,SORT,DISTINCT. Unlees I missing something