Wikidata:WikiProject Linked Data for Production/Practical Wikidata for Librarians/Queries

People who won the Margaret Mann Citation award for excellence in cataloging

edit
SELECT ?Margaret_Mann_Citation ?Margaret_Mann_CitationLabel WHERE {
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
  ?Margaret_Mann_Citation wdt:P166 wd:Q22116013.
}
LIMIT 100
Try it!

Items with an ISSN, Online Books Page ID, start and end date

edit
#ISSN serial IDs

SELECT ?wikidataid ?olbpid ?article ?start ?end
       (group_concat(?issn) as ?issns)
WHERE
  {?wikidataid wdt:P236 ?issn .
  OPTIONAL {?article schema:about ?wikidataid .
            ?article schema:inLanguage "en" .
            ?article schema:isPartOf <https://en.wikipedia.org/> }
  OPTIONAL {?wikidataid wdt:P5396 ?olbpid}
  OPTIONAL {?wikidataid wdt:P571 ?start}
  OPTIONAL {?wikidataid wdt:P576 ?end}
}
GROUP BY ?wikidataid ?article ?olbpid ?start ?end
ORDER BY ?wikidataid
LIMIT 100000
Try it!

People who have ever been employed by Stanford without LCNAFs

edit
SELECT ?human ?humanLabel
WHERE
{
    ?human wdt:P108 wd:Q41506 . #last parameter is institution
    FILTER NOT EXISTS { ?human wdt:P244 ?o } . #limits to people without LCNAF in Wikidata; delete this line to get everyone
    SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" }
}
Try it!

Query for an item by Library of Congress Name Authority ID

edit
SELECT ?person ?personLabel 
WHERE 
{
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
  ?person wdt:P244 ?lc.
  FILTER (?lc="n99260517")
}
Try it!

Different items with the same identifier

edit
#Unique value constraint report for P244: report listing each item
SELECT DISTINCT ?item1 ?item1Label ?item2 ?item2Label ?value 
{
	?item1 wdt:P244 ?value . #use different predicate for a different identifier
	?item2 wdt:P244 ?value . #use same predicate as previous statement
    ?item1 wdt:P31 wd:Q5 .
    ?item2 wdt:P31 wd:Q5 .
	FILTER( ?item1 != ?item2 && STR( ?item1 ) < STR( ?item2 ) ) .
	SERVICE wikibase:label { bd:serviceParam wikibase:language "en" } .
}
LIMIT 1000
Try it!

Query for people born between 1602 and 1880 without a death date

edit
SELECT ?h ?date
WHERE
{
	?h wdt:P31 wd:Q5 .
	?h wdt:P569 ?date .
	OPTIONAL {?h wdt:P570 ?d }
	FILTER (?date > "1601-01-01T00:00:00Z"^^xsd:dateTime)
	FILTER (?date < "1880-01-01T00:00:00Z"^^xsd:dateTime)
	FILTER (!bound(?d))
}
LIMIT 100
Try it!

Query for people employed at Penn State without position held qualifier

edit
SELECT DISTINCT ?human ?humanLabel WHERE {
  ?human wdt:P108 wd:Q739627. # employer is Penn State University, change final value to your employer
  ?item p:P108 ?employment_statement.
  ?employment_statement ps:P108 wd:Q739627.
  FILTER(NOT EXISTS { ?employment_statement pq:P39 ?o. }) # this tests to see if the person has a position held qualifier
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}

LIMIT 100
Try it!

Query for African-American librarians with no article on the English Wikipedia

edit
SELECT DISTINCT ?item ?itemLabel  
WHERE
{
?item wdt:P106/wdt:P279* wd:Q182436 ;
      wdt:P172 wd:Q49085 .
     
	# look for articles (sitelinks) 
  	OPTIONAL { ?sitelink schema:about ?item . ?sitelink schema:inLanguage "en" }
	# but select items with no such article
	FILTER (!BOUND(?sitelink))

	# humans only
  	?item wdt:P31 wd:Q5 .
  
   SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
Try it!