Amleth
Amleth

Reputation: 1

SPARQL query that detects triples existing in two graphs

I try to write a SPARQL query to detect duplicated RDF triples that exist in two given graphs (on the same endpoint), but don't know how to do it.

Is it feasible, and if so, how?

Upvotes: 0

Views: 52

Answers (1)

SELECT DISTINCT * 
WHERE {
  GRAPH <https://example.com/named-graph-1/> { ?s ?p ?o . }
  GRAPH <https://example.com/named-graph-2/> { ?s ?p ?o . }
}

To find duplicate triples in any two named graphs, you can use variables:

SELECT DISTINCT *
WHERE {
  GRAPH ?namedGraph1 { ?s ?p ?o . }
  GRAPH ?namedGraph2 { ?s ?p ?o . }
  FILTER( STR(?namedGraph1) < STR(?namedGraph2) )
}

Upvotes: 3

Related Questions