Search code examples
sparqlrdf

SPARQL: how to also SELECT the Object that I inspect as a result of the query


Here a SPARQL query:

PREFIX : <...#>

SELECT *
WHERE { {  :Airspace_LSAGE_411 ?p ?o . }
UNION {  :Airspace_LSAGN_411 ?p ?o . }
UNION {  :Airspace_LSAGS_411 ?p ?o . }
}  LIMIT 2000

This will get me the properties and associated values of the three airspace-objects Airspace_LSAGE_411, Airspace_LSAGN_411, Airspace_LSAGS_411.

The Problem is that in the result table, I only have the columns p and o. So I do not know which row belongs to which airspace, for example:

p       o
----    ----
:color  red
:color  blue

Is it possible to repeat the airspace name in the result to get something like this:

s                     p       o
----                  ----    ----
Airspace_LSAGE_411    color  red
Airspace_LSAGN_411    color  blue

I know that differentiation should be easy by doing three queries, one after the another, but my main point is how to get complete triples as a result.


Solution

  • Use VALUES to provide the data inline.

    SELECT  ?s ?p ?o
    {VALUES ?s { :Airspace_LSAGE_411 :Airspace_LSAGN_411 :Airspace_LSAGS_411}
    ?s ?p ?o. }