N1QL update query

I need to update an object in a document(type : x) with new values which are present in other document(type : y). There are three documents which are required for this : x, y and z. ‘X’ document is having a reference of both y and z. Whereas ‘Z’ is having reference of y. Now i need to update z reference in ‘X’ document with new values of ‘Z’. And for this i will use ‘Y’ reference which is being used both in ‘X’ and ‘Z’.

update vs set vs.visitTarget.Refs.subUnit.text = su.name, vs.visitTarget.Refs.subUnit.id = su.awId
from core vs join core bu on keys vs.awRefs.Unit.id
join core su on keys (—join between BU and SU—)
where vs.Type=‘company’ and bu.Type=‘Unit’ and su.Type='subunit’
and substr(lower(vs.Refs.Unit.remoteKey),0,1) != substr(lower(vs.visitTarget.Refs.subUnit.text),0,1)

I have got to know that we cannot use join with update in n1ql. Is there a way to update a document with details of other document at run-time?

Check out MERGE-UPDATE or subquries

@sandeep.deshwal

Plese see examples at: Using MERGE to update matched items from a SELECT
Within the USING clause, you can have any complex SELECT statement.

Once you have the matching documents, you can UPDATE as you need.