Hi! How can I modify this Couchbase Lite Query to correctly return the distinct count of tasks and notes, along with an accurate sum of both? Right now, the query inflates the values.
For example, I expect COUNT(task) to be 1, COUNT(note) to be 12, and (COUNT(task) + COUNT(note)) to be 13, but I’m getting 13, 13, and 26 instead.
SELECT
tag.id,
tag.name,
COUNT(task) AS taskCount,
COUNT(note) AS notesCount,
(COUNT(task) + COUNT(note)) AS numberOfTimesUsed
FROM temp.tags AS tag
LEFT JOIN temp.tasks AS task ON ARRAY_CONTAINS(task.tagIds, tag.id)
LEFT JOIN temp.notes AS note ON ARRAY_CONTAINS(note.tagIds, tag.id)
GROUP BY tag.id