Contact FutureLearn for Support
Skip main navigation
We use cookies to give you a better experience, if that’s ok you can close this message and carry on browsing. For more info read our cookies policy.
We use cookies to give you a better experience. Carry on browsing if you're happy with this, or read our cookies policy for more information.


Suppose that for some reason you want to construct triples for albums made either by the Beatles or by the Smashing Pumpkins (or both).

Including both of these constraints in the WHERE list will not work, because implicitly the list represents a conjunction of statements, each of which must be satisfied.

To allow disjunctions, SPARQL contains a UNION pattern; this is formed by placing the keyword UNION between two subsets of statements, each subset delimited by curly brackets. The meaning is that variable bindings should be retrieved if they satisfy either the statements on the left or the statements on the right (or both). Thus our target query is formed as follows:

PREFIX dbpedia: <>
PREFIX foaf: <>
PREFIX dc: <>
PREFIX mo: <>

CONSTRUCT { ?album dc:creator ?band .
            ?track dc:creator ?band .
WHERE { ?band foaf:made ?album .
        ?album mo:record ?record .
        ?record mo:track ?track .
        { ?band foaf:name "The Beatles" }
        { ?band foaf:name "The Smashing Pumpkins" }

Note that the first three statements of the WHERE list lie outside the scope of the UNION operator.

Share this article:

This article is from the free online course:

Introduction to Linked Data and the Semantic Web

University of Southampton

Course highlights Get a taste of this course before you join:

  • Welcome to the course
    Welcome to the course

    Watch Dr Elena Simperl & Dr Barry Norton explain how this short course on linked data & the semantic web can help you use this technology in your work

  • Developing real world applications
    Developing real world applications

    Watch Dr Barry Norton describing some real world applications that have Linked Data as their underlying technology.

  • Welcome to Week 2
    Welcome to Week 2

    Watch Dr Barry Norton explain what you will learn about SPARQL (the query language) on this course and what you will be practicing.