I´m trying to write a SELECT, that gives me all the Values in a Table. I have optional Values, I want those to be filled with a standard value, If they don´t exist.
This is my code:
SELECT * WHERE {
?a nmo:hasObject nm:coin
OPTIONAL
{ ?a nmo:hasAuthority ?b }
OPTIONAL
{ ?a nmo:hasMaterial ?c }}
What I get id the following:
?a ?b ?c
1 yx
2 ab
3 xz bc
What I want is to fill it up with the String "missing" if there is no value:
?a ?b ?c
1 yx "missing"
2 "missing" ab
3 xz bc
Any ideas on how to structure the SELECT to get this output?
I'd probably use coalesce here:
SELECT
?a
(coalesce (?b, ?missing) as ?bb)
(coalesce (?c, ?missing) as ?cc)
WHERE {
VALUES ?missing { "missing" }
?a nmo:hasObject nm:coin
OPTIONAL
{ ?a nmo:hasAuthority ?b }
OPTIONAL
{ ?a nmo:hasMaterial ?c }
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With