Hello all, I would like to ask a question about the OPTIONAL clause.
Suppose we have this graph pattern:
Even in this case, where the variables are not the same, so they are not "joined", if there are no triples that match for example the third triple pattern, then the whole query is going to give me nothing as result. How is it possible that the triples are connected, even though they have nothing in common?
I would imagine that even if there is nothing in the ?email variable I would get a cross product for the three variables that would contain something like NULL or empty string for the ?email.
This problem happens also when I am not SELECTing the ?email variable. If there are no triples that match, I get no answer for all the SELECTed variables.
Of course, one would say to use OPTIONAL for every triple pattern so that to be sure that I get results back. And yes, when I am using it I get results, even if the last triple pattern match no triples. However, I would prefer to find a way not to use the OPTIONAL clause. Any ideas?
Thank you very much for your time!
If you want to get result whether or not a triple pattern matches, that means that you accept that it possibly do not match. "Possibly" is synonymous with "optionally", so you really want the triple to be OPTIONAL. End of the story.
However, if you want all the places and all the movies and all the emails in the same query without using OPTIONAL, you can also use a union:
but this will give you back a table where each line has exactly two NULL values.
PS: there is nothing extraordinary here. You mention NULL in your question, so I guess you are familiar with SQL. In SQL, it is the same. Consider the query
answered 08 Dec '12, 04:18
Antoine Zimm... ♦