Hi, There is a general caveat when building SPARQL Unions of Subqueries in Virtuoso which I believe is unnecessary.
The following query works fine. select distinct ?s ?text where { { ?s rdfs:label ?text } union { ?s rdfs:comment ?text } } limit 10 But assume I want to complicate it a bit by using subqueries ( in this case it makes no sense, but there are definitely use cases for this, like combing results of complex queries ) select distinct ?s ?text where { { select ?text where {?s rdfs:label ?text} } union { select ?text where {?s rdfs:comment ?text} } } limit 10 The latter query will yield an error: 37000 Error SP031: SPARQL compiler: Variable 's' is used in the query result set but not assigned So, it follows that I need to bind the variables at least once in the outer pattern. Fine, I can do that: select distinct ?s ?text where { ?s ?p ?text . { select ?text where {?s rdfs:label ?text} } union { select ?text where {?s rdfs:comment ?text} } } limit 10 And it works ;) But, here's the observation: Why do I HAVE to declare the variables outside? Isn't there any way that the compiler can detect which variables are being referenced in the select projections part? When dealing with complex queries I usually find myself writing dummy BGPs, for example: ?interestingSubject ?xx1 ?xx2 . ?xx3 ?xx4 ?interestingObject . { subquery1... } union { subquery2...} union {subquery3...} Will enabling this "automatically" introduce ambiguity? Regards, A -- Aldo Bucchi skype:aldo.bucchi http://www.univrz.com/ http://aldobucchi.com/ PRIVILEGED AND CONFIDENTIAL INFORMATION This message is only for the use of the individual or entity to which it is addressed and may contain information that is privileged and confidential. If you are not the intended recipient, please do not distribute or copy this communication, by e-mail or otherwise. Instead, please notify us immediately by return e-mail.