Alright, I may be pushing it a little now…
I have this select statement that returns data combined from two documents:
SELECT t2.name, t1.`key`,t1.yearborn,t2.email,
ifmissingornull(t2.cellphone,ifmissingornull(t2.phone,'-')) as phone,
FROM data AS t1
LEFT JOIN data AS t2 ON 'User:Private:' || t1.`key` = META(t2).id AND t2.type='Private'
WHERE t1.type='User'
Now I want to also find the newest fishing trip and count of all fishing trips by this user using the userkey on the trip. So I have tried something like this (which is not valid syntax):
SELECT t2.name, t1.`key`,t1.yearborn,t2.email,
ifmissingornull(t2.cellphone,ifmissingornull(t2.phone,'-')) as phone,
c
FROM data AS t1
LEFT JOIN data AS t2 ON 'User:Private:' || t1.`key` = META(t2).id AND t2.type='Private'
let c = select count(*) from data f where f.type='FishingTrip' and f.userkey=t1.`key`
WHERE t1.type='User'
This may be closer but still not valid syntax:
SELECT t2.name, t1.`key`,t1.yearborn,t2.email,
ifmissingornull(t2.cellphone,ifmissingornull(t2.phone,'-')) as phone,
count(t3) count
FROM data AS t1
LEFT JOIN data AS t2 ON 'User:Private:' || t1.`key` = META(t2).id AND t2.type='Private'
left join data as t3 on t1.`key` = t3.userkey and t3.type='FishingTrip'
WHERE t1.type='User'
The error message is:
There may be users that don’t yet have a fishing trip - so the query must be robust enough to handle that…
Can this be done?