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.

Queries using CONSTRUCT

In this step, you will learn how CONSTRUCT queries return new RDF graphs.

When building an application like the music portal, you might need to retrieve some information from a queried dataset and re-express it in new RDF triples, perhaps using new names for resources. This might, for example, allow more efficient integration with triples from another dataset.

To meet this need, SPARQL provides a CONSTRUCT query which uses information retrieved from a dataset in order to build new RDF statements.

Note that the query does not update the dataset. The new RDF triples are returned to the user as output, to be used in any way desired, the dataset itself remaining unchanged. (In SPARQL 1.1 there are query types for updating a dataset, as described in a later section of this chapter.)

CONSTRUCT queries

To show the basic syntax of a CONSTRUCT query, consider the following example where the user wishes to assert “creator” relationships between artists and their products – of any kind; perhaps the aim is to construct a dataset in which this predicate is used consistently, replacing more specific predicates in MusicBrainz.

    PREFIX dbpedia: <http://dbpedia.org/resource/>
    PREFIX foaf: <http://xmlns.com/foaf/0.1/>
    PREFIX dc: <http://purl.org/dc/elements/1.1/>
    PREFIX mo: <http://purl.org/ontology/mo/>

    CONSTRUCT { ?album dc:creator dbpedia:The_Beatles .
                ?track dc:creator dbpedia:The_Beatles .
          }
    WHERE { dbpedia:The_Beatles foaf:made ?album .
            ?album mo:record ?record .
            ?record mo:track ?track . 
      }

The key to understanding this query is that the variables employed in the CONSTRUCT list must occur also in the WHERE list. When the query is run, the query engine begins by retrieving the variable bindings satisfying the description in the WHERE list – just as it would for a SELECT query.

For each variable binding, it then instantiates the triple patterns in the CONSTRUCT list and so creates (in this case two) new RDF triples. The result of the query is a merged graph including all the created triples.

The figure above shows this outcome diagrammatically for an even simpler CONSTRUCT query, with the relevant part of the dataset and the constructed triples both shown as graphs.


In the next step, you will be able to practice organising the results of CONSTRUCT queries.


This work is a derivative of ‘Using Linked Data Effectively’ by The Open University (2014) and licensed under CC by 4.0 International Licence adapted and used by the University of Southampton. http://www.euclid-project.eu/

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
    video

    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
    video

    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
    video

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