A typical SPARQL query that specifies a graph might look like this:
SELECT ?b ?c WHERE { GRAPH {
?b ?c}
Yes
SELECT ?b ?c
FROM NAMED <http://AliceIRI>
FROM NAMED <http://BobIri>
WHERE
{
GRAPH ?g { <http://local.virt/foo> ?b ?c }
}
FROM NAMED
clauses may be used to set named graphs that are queried when you use a GRAPH ?var
clause.
It is important to note that semantically this query is identical to what you wrote above so the pattern expressed by the GRAPH
clause is matched against each named graph separately and unioned together
Edit
To answer the extra question in your comment yes you can, if you use FROM
instead of FROM NAMED
this sets the default graph for the query to be the merge of all graphs in FROM
clauses and does not require you to use GRAPH
e.g.
SELECT ?b ?c
FROM <http://AliceIRI>
FROM <http://BobIri>
WHERE
{
<http://local.virt/foo> ?b ?c
}
This covers the case where you want to allow triples that match different parts of the triple pattern come from any of the graphs you have named.
Note that some triple stores may allow you to set them up so that the default graph is automatically treated as the merge of all named graphs.
If you have to run a query in a subset of the graphs that you are using you can also set a filter on the iri of the graphs.
eg:
SELECT ?b ?c
FROM NAMED <http://AliceIRI>
FROM NAMED <http://BobIri>
FROM NAMED <http://CarlIri>
WHERE {
GRAPH ?g {
<http://local.virt/foo> ?b ?c
FILTER( ?g=<http://AliceIRI> || ?g=<http://BobIri> )
}
}