XQuery - Deleting using joins

Hello!

I have problem with a - in my opinion - complex XQuery.

I have three doctypes and want to do a nested delete.

doctype b depends on doctype a
doctype c depends on doctype b

So for example:
If a delete a element in doctype a where aID = 5, i want to delete all doctypes b where aID = bID. So far, seems no problem. But now I also want to delete all doctypes c where $cOtherID = $bOtherID AND the above options matches.

Get all elements with:

for $a in input()/docA
for $b in input()/docB
where $a/ID = $b/ID
and $b/ID = 5
return

{$a/ID}
{$b/otherID}
{for $c in input()/docC
where $c/otherID = $b/otherID
return $c/anotherValue }


It works fine. Gives me a list like that:


5
1
1
3
4


Now, i want to rewrite this query to delete all doctypes a,b and c where the query returns values.

Any ideas? Or should I split this into different queries? One query would be great.

Thanks in advance.

Regards,
Christian

Hi,

You can use an FLWU expression to perform the delete operation. The following statement should do the job:

update
for $a in input()/docA
for $b in input()/docB
let $d := for $c in input()/docC
where $c/otherID = $b/otherID
return $c
where $a/ID = $b/ID
and $b/ID = 5
do
(
delete $a
delete $b
delete $d
)

Regards,
Thorsten

Hi Thorsten!

Thanks again for your help!

Just one thing missing in your query.
Has to be

 
do
( 
delete $a/..
delete $b/..
delete $d/..
)



to delete all root element.

Regards,
Christian