Search code examples
sparqlsparqlwrapper

SPARQL combine - concatenate two columns into one


I'm a newbie to SPARQL, and I would like to combine two columns into one

initial table

a|b|1
c|d|2

wanted table

a|b
c|d
b|1
d|2

its like creating two different tables and putting them one on the other.

I need that to make a visualisation using d3sparql which takes this data form, I also though about importing a json and modifying it then printing it to the screen, but if this is possible that makes things a lot easier and faster..


UPDATE: My original Query looks like that

PREFIX prefix1:<...>
PREFIX prefix2:<...>
SELECT ?x ?y ?z 
WHERE  { 
?x prefix1:OwnsY ?y.
?y prefix1:PublishesZ ?z.
}

Solution

  • The simplest way (but not the most efficient) is:

    PREFIX prefix1:<...>
    PREFIX prefix2:<...>
    SELECT DISTINCT ?x ?z 
    WHERE  {
        { ?x prefix1:OwnsY ?y. ?y prefix1:PublishesZ ?z. }
        UNION
        { ?x prefix1:OwnsY ?z. ?z prefix1:PublishesZ ?whatever. }
    }
    

    which in effect performs the query twice.