Union

A graph pattern is made up of several triples—all of which have to match in order for the pattern to match. In logical terms, this means that there is an implicit “and” operation between the triples. One could correctly read a graph pattern as saying “the first triple matches AND the second triple matches AND the third triple matches …” But there are times when we might want to say that this triple matches OR that triple matches. For those times, SPARQL provides UNION.

UNION combines two graph patterns, resulting in the set union of all bindings made by each pattern. Variables in each pattern take values independently (just as they do in subqueries), but the results are combined together.

A simple example would be to find out all the actors ...

Get Semantic Web for the Working Ontologist, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.