@vsr1 I am trying this solution in the below query and getting error.
SELECT d.id,
h AS historyid
FROM pure-ecs-cms d
UNNEST d.history AS h
WHERE type=“page”
AND ARRAY_LENGTH(d.history) > 0
AND (d.isStack IS MISSING OR d.isStack <> TRUE)
AND (d.isschedul IS MISSING OR d.isschedul <> TRUE)
AND (d.sup=0 OR d.sup IS MISSING)
AND d.id NOT IN ( SELECT DISTINCT RAW k.iref FROM pure-ecs-history k WHERE k.type = “history”)
WITH ahistory AS (SELECT DISTINCT RAW k.iref FROM `pure-ecs-history` k WHERE k.type = "history" AND k.iref IS NOT NULL)
SELECT d.id, h AS historyid
FROM `pure-ecs-cms` d
UNNEST d.history AS h
WHERE d.type = "page" AND ARRAY_LENGTH(d.history) > 0
AND IFMISSING(d.isStack, false) != true
AND IFMISSING(d.isschedul, false) != true
AND IFMISSING(d.sup, 0) = 0
AND d.id NOT IN ahistory;
[
{
“code”: 3000,
“msg”: “Ambiguous reference to field type.”,
“query”: “WITH ahistory AS (SELECT DISTINCT RAW k.iRef FROM pure-ecs-history k WHERE k.type = “history” AND k.iRef IS NOT NULL)\nSELECT d.id,\n h as historyid \nFROM pure-ecs-cms d\nUNNEST d.history as h\nWHERE type=“page”\n AND ARRAY_LENGTH(d.history) > 0\n AND IFMISSING(d.isStack, false) != true\n AND IFMISSING(d.isschedul , false) != true\n AND IFMISSING(d.sup, 0 ) = 0\n AND d.id NOT IN ahistory”
}
]