I am trying to combine 2 Queries where i get a list of all my tracts as well as pull from my farm all emails which are not bounced etc and return as one.
the first query i have is straight forward and simple
SELECT name, tract_id from Contacts where _type = 'tract_info'
and my return looks like this
[ {
"name": "Mariners Bluff",
"tract_id": [ 12339, 12335, 12335, 12336, 12337, 12338 ]
},
{
"name": "Cabo del Mar",
"tract_id": [ 13260, 13261 ]
}]
here is a sample query to get a list of all emails which i don’t need just the total count
SELECT COUNT(e.address)
FROM Contacts c
UNNEST c.emails e
WHERE c._type= 'farm'
AND ARRAY_COUNT(c.emails) > 0
AND e.bounce IS MISSING
AND (e.dnmm IS MISSING
OR e.dnmm = FALSE)
AND c.tract IN [ 12339, 12335, 12335, 12336, 12337, 12338 ]
So i tried it via subquery below with no luck , So how can i achieve this goal ?
SELECT d.name,
(
SELECT COUNT(e.address)
FROM Contacts c
UNNEST c.emails e
WHERE c._type= 'farm'
AND ARRAY_COUNT(c.emails) > 0
AND e.bounce IS MISSING
AND (e.dnmm IS MISSING
OR e.dnmm = FALSE)
AND c.tract IN d.tract_id ) AS EmailCount
FROM Contacts d
WHERE d._type = 'tract_info'`