SERVICE Keyword
The core of SPARQL federation. Learn syntax, variable passing, and how to structure federated queries effectively.
Learn SERVICEQuery the entire Linked Data web. Use SERVICE to combine data from multiple SPARQL endpoints in a single query — Wikidata, DBpedia, and beyond.
No single knowledge base contains all the information you need. Wikidata might have an entity, but DBpedia has additional details, or another specialized endpoint has domain-specific data.
SPARQL federation solves this with the SERVICE keyword. Execute parts
of your query against remote endpoints and combine results seamlessly — all from
a single query.
This is the vision of the Semantic Web: interconnected data that can be queried as if it were a single giant database.
SELECT ?localVar ?remoteVar
WHERE {
# Local patterns (run on current endpoint)
?item wdt:P31 wd:Q9143 .
# Remote patterns (run on external endpoint)
SERVICE <http://dbpedia.org/sparql> {
?dbpediaItem owl:sameAs ?item .
?dbpediaItem foaf:homepage ?remoteVar .
}
}
The query engine sends the SERVICE block to the remote endpoint,
receives the results, and joins them with local results based on shared variables.
The core of SPARQL federation. Learn syntax, variable passing, and how to structure federated queries effectively.
Learn SERVICEDiscover useful public endpoints: DBpedia, Getty Vocabularies, Europeana, and domain-specific knowledge bases.
Explore EndpointsCommon patterns for effective federation: entity linking, enrichment, cross-validation, and aggregation.
View PatternsSELECT ?lang ?langLabel ?homepage
WHERE {
# Get programming languages from Wikidata
?lang wdt:P31 wd:Q9143 .
# Get homepage from DBpedia via sameAs link
SERVICE <http://dbpedia.org/sparql> {
?dbpediaLang owl:sameAs ?lang ;
foaf:homepage ?homepage .
}
SERVICE wikibase:label {
bd:serviceParam wikibase:language "en" .
}
}
LIMIT 10
SELECT ?lang ?langLabel ?homepage
WHERE {
?lang wdt:P31 wd:Q9143 .
# SILENT: Don't fail if endpoint is unavailable
SERVICE SILENT <http://dbpedia.org/sparql> {
?dbpediaLang owl:sameAs ?lang ;
foaf:homepage ?homepage .
}
SERVICE wikibase:label {
bd:serviceParam wikibase:language "en" .
}
}
LIMIT 10
| Endpoint | URL | Domain |
|---|---|---|
| Wikidata | https://query.wikidata.org/sparql |
General knowledge |
| DBpedia | http://dbpedia.org/sparql |
Wikipedia data |
| Getty Vocabularies | http://vocab.getty.edu/sparql |
Art & cultural heritage |
| UniProt | https://sparql.uniprot.org/sparql |
Proteins & biology |
| LinkedGeoData | http://linkedgeodata.org/sparql |
OpenStreetMap data |
Congratulations! You've learned SPARQL from basic queries to advanced federation. Continue exploring with more examples or revisit any chapter.
Review ASK, CONSTRUCT, and DESCRIBE.
Go BackReview the basics or explore more examples.
Basic Queries