• +49-(0)721-402485-12
Ihre Experten für XML, XQuery und XML-Datenbanken

Formulation of a full outer join

Now, the alternative asymmetric formulation of a left or right outer join shown on the previous page can be used in order to formulate a full outer join in XQuery. One side is realised according to the principle of the nesting, the other side according to the principle of the bisection of the result document, as shown before.

Realistically, one cannot assume, for example, that each doctor lives in a city in which also a patient lives. Therefore, a full outer join is needed in order to obtain all patient items as well as all doctors in the result document. The appropriate query combines in this way the left and the right outer join to a query with a full outer join:

<EmergencyList>
(: all patients with emergency doctor, if possible :)
<Patients>
{
for $p in fn:collection("Patients")
order by $p//LastName, $p//FirstName
return
<Patient>
{ $p/*/Name,
for $d in fn:doc("Hochwaldklinik.xml")//Doctor
where $p//Address/City = $d//Address/City
return
<EmergencyDoctor>
{ $d//FirstName }
{ $d//LastName }
</EmergencyDoctor>
}
</Patient>
}
</Patients>,

(: doctors without emergency patients :)
<Stand-InDoctors>
{
for $d in fn:doc("Hochwaldklinik.xml")//Doctor 
where fn:empty(fn:collection("Patients)/Address
[./City = $d//Address/City])
order by $d//LastName, $d//FirstName
return
<EmergencyDoctor>
{ $d//FirstName }
{ $d//LastName }
</EmergencyDoctor>
}
</Stand-InDoctors>
}
</EmergencyList>

This example impressively illustrates the effort which is required to specify complexly structured result documents in a XQuery query. However, this effort faces the enormous flexibility in the structuring of the result.

 

Source: "XQuery – Grundlagen und fortgeschrittene Methoden", dpunkt-Verlag, Heidelberg (2004)

<< backnext >>