Topic on User talk:TweetsFactsAndQueries

Jump to navigation Jump to search

Wikidata:SPARQL query service/queries/examples#Simple Queries

6
Summary by TweetsFactsAndQueries

two questions around VALUES

92.227.37.75 (talkcontribs)

Wikidata:SPARQL_query_service/queries/examples#Simple_Queries

Maybe one can add an example for getting data by QID? I propose Einstein and Bach : Q937, Q1339 and something that normally should have a single value, e.g. P25 mother. SELECT ?item ?itemLabel ?mother ?motherLabel WHERE {

 ?item IN SET {????????}
 OPTIONAL { ?item wdt:P25 ?mother. }
 SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }

}

TweetsFactsAndQueries (talkcontribs)

I think you’re looking for VALUES:

SELECT ?item ?itemLabel ?mother ?motherLabel WHERE {
  VALUES ?item { wd:Q937 wd:Q1339 }
  OPTIONAL { ?item wdt:P25 ?mother. }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}

Try it!

85.180.178.124 (talkcontribs)
85.179.161.128 (talkcontribs)

I would like to add an example for selection by values of a specific property, but get "Query is malformed: Encountered " <PNAME_LN> "wdt:213 "" at line 2, column 16." for:

SELECT ?item ?itemLabel ?mother ?motherLabel ?ISNI WHERE {
  VALUES ?item wdt:213 { "0000 0001 2281 955X" "0000 0001 2276 4157"}
  OPTIONAL { ?item wdt:P25 ?mother. }
  OPTIONAL { ?item wdt:P213 ?ISNI. }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}

Try it!

TweetsFactsAndQueries (talkcontribs)

That works like this:

SELECT ?item ?itemLabel ?mother ?motherLabel ?ISNI WHERE {
  VALUES ?ISNI { "0000 0001 2281 955X" "0000 0001 2276 4157" }
  ?item wdt:P213 ?ISNI.
  OPTIONAL { ?item wdt:P25 ?mother. }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}

Try it!

You first define the ISNI values you’re interested in and then search for items with those values.

85.179.161.128 (talkcontribs)