this query outputs twins. For this it combines the following sets of items using UNION:
- entities that are instances of the "twin" class
- entities that have a biological sibling born on the same date
My problem is that people who fit both criteria appear in the results list twice. For example #31 and #32 (Princess Josephine of Denmark). How do I make it so that if there are available values for ?twin_2_name and ?twin_2_desc, they are output, but not the version with values "-"?
Those missing values should only be output for people like #11 (Mario Andretti) who are a "twin", but for which twin sibling info is missing. I tried using BIND(COALESCE(...)) but had no luck. I also tried running it in WDQS, but even if I strip most of the parts of the query away, I get a timeout.
The query text in case the link is broken/wrong again:
SELECT DISTINCT ?twin_name ?twin_desc ?date_birth ?twin_2_name ?twin_2_desc
WHERE
{ { ?twin wdt:P31/(wdt:P279)* wd:Q159979 .
?twin wdt:P569 ?date_birth
}
UNION
{ { { ?twin p:P569 ?p569 .
?p569 rdf:type wikibase:BestRank ;
psv:P569 ?psv569 .
?psv569 wikibase:timePrecision ?time_precision
}
FILTER ( ?time_precision >= 11 )
?psv569 wikibase:timeValue ?date_birth
{ ?twin wdt:P25 ?mother }
UNION
{ ?twin ^wdt:P40 ?mother .
?mother wdt:P21 wd:Q6581072
}
?mother wdt:P40 ?twin_2 .
?twin_2 wdt:P569 ?date_birth
}
FILTER ( ?twin != ?twin_2 )
?twin_2 rdfs:label ?twin_2_name
FILTER ( lang(?twin_2_name) = "en" )
?twin_2 schema:description ?twin_2_desc
FILTER ( lang(?twin_2_desc) = "en" )
}
?twin schema:description ?twin_desc
FILTER ( lang(?twin_desc) = "en" )
?twin rdfs:label ?twin_name
FILTER ( lang(?twin_name) = "en" )
?twin ^schema:about/wikibase:sitelinks ?sitelinks
}
ORDER BY DESC(?sitelinks)