SPARQL/UNION

From testwiki
Revision as of 14:34, 2 August 2023 by imported>HoboMcJoe (copyedit)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Template:Nav

Suppose the set A: 28 capitals in European Union Template:SPARQL

Suppose the set B: 3 cities with millions of inhabitants in European Union. Template:SPARQL

The intersection of A and B, big capitals of the European Union, can simply be achieved by combining all the triples. This results in 1 city. Template:SPARQL

All capitals of the European union, excluding big cities can be achieved by filtering using FILTER NOT EXISTS { }. This results in the other 27 capitals. Template:SPARQL

Finally a UNION of capitals and big cities result in 30 cities, one of which was deduplicated by DISTINCT. Template:SPARQL Mind that the 2 parts of the union should both be within brackets { ... } UNION { ... }.

Two simpler examples of UNION are

The last code can be simplified by using property path ?child wdt:P22|wdt:P25 ?parent.

An overview of all kind of joins:

Venn diagram Mathematical SPARQL
AB And A.
B.
AB A.
FILTER NOT EXISTS{ B. }
A A.
OPTIONAL{ B. }
AB Or { A. } UNION { B. }

Template:Nav Template:BookCat