Search code examples
sparqlunion

Sparql operation on union of two queries


I have two sparql querys , simplifying my problem :

query 1:

 select ?letter ?number 

-> results ({a1}{b2}{d4})

.... query 2:

 select ?anotherletter ?anotherNumber 

-> results ({b2}{c3})

How can i join the 2 querys to obtain the sum of the second column, maybe same values of a one lista couldnt be in the second. The result of the query has to be

{a,1}{b,4}{c,3}{d,4}

Is there a propper way to do that?


Solution

  • The solution that gives @UninformedUser worked:

    select ?letter (sum(?number) as ?cnt) {  {QUERY1} UNION {QUERY2} } group by ?letter
    

    and yes, the variables should be the same in both UNION parts. – UninformedUser