What is a named graph?

In an RDF database, a named graph is what we call a subset of our data that has been given a unique label (name). A graph database can contain any number of named graphs alongside its default graph, and each fact can be present in or absent from any graph.

A Named Graph Example

Suppose we have the following company data in the named graph :OfficialRecords

:alice :hasJob :softwareDeveloper .
:bob :hasJob : softwareDeveloper .
:charles :hasJob :accountant .

And the following data in the named graph :SurveyAnswers

:alice :likes :photography .
:bob :likes :basketball .
:charles :likes :music .

We can combine the knowledge in both graphs to find the hobbies of the software developers in this company:

SELECT ?hobby WHERE {
   GRAPH :OfficialRecords {?employee :hasJob :softwareDeveloper} .
   GRAPH :SurveyAnswers {?employee :likes ?hobby}
}

We can also use a variable in place of a graph name to return all the information about the employees:

SELECT * WHERE { GRAPH ?g { ?a ?b ?c } }
Down arrow icon.