query-900f970b5429ba20f8f0488be26b7a99
How to randomly select 100 male persons?It seems most examples of randomisation in SPARQL use RAND with ORDER BY, so I tried the following two queries, but I always get timeout. I guess there are too many people in Wikidata and the use of ORDER BY cannot handle. Any idea how to get the list of random 100 male persons (with Wikipedia links)? Many thanks!
Use at
- https://query.wikidata.org/sparql
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX schema: <http://schema.org/>
SELECT
DISTINCT ?person ?sitelink ?random
WHERE{
?person wdt:P31 wd:Q5 .
?person wdt:P21 wd:Q6581097 .
?sitelink schema:about ?person .
?sitelink schema:inLanguage "en" .
?sitelink schema:isPartOf <https://en.wikipedia.org/> .
BIND(RAND() AS ?random) .
}
ORDER BY ?random
LIMIT 100
Query found at
- https://www.wikidata.org/wiki/Wikidata:Request_a_query/Archive/2022/12
- https://www.wikidata.org/wiki/Wikidata:Request_a_query/en
- https://www.wikidata.org/wiki/Wikidata:Request_a_query/es
- https://www.wikidata.org/wiki/Wikidata:Request_a_query/fr
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v2("?person"):::projected
v4("?random"):::projected
v3("?sitelink"):::projected
c9([https://en.wikipedia.org/]):::iri
c2(["wd:Q5"]):::iri
c4(["wd:Q6581097"]):::iri
c7(["en"]):::literal
v2 --"wdt:P31"--> c2
v2 --"wdt:P21"--> c4
v3 --"schema:about"--> v2
v3 --"schema:inLanguage"--> c7
v3 --"schema:isPartOf"--> c9
bind0[/"RAND()"/]
bind0 --as--o v4