Hiba Arnaout
Hiba Arnaout

Reputation: 73

Wikidata SPARQL interface: order by random

I've been playing a little bit with the Wikidata SPARQL page (here), and I was wondering if we can shuffle the order of the results set randomly.

I tried the following example, and I left the random part as a comment cause I couldn't find the correct syntax for it:

SELECT ?partyLabel ?countryLabel ?count
WHERE{
?party wdt:P31 wd:Q7278.
  ?party wdt:P17 ?country.
  ?party wdt:P2124 ?count
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en".}
}
order by #random
limit 15

Did anyone try the random ordering option? and does it exist?

Upvotes: 2

Views: 834

Answers (1)

Stanislav Kralin
Stanislav Kralin

Reputation: 11479

Possible candidates are:

However, neither ORDER BY RAND() nor ORDER BY BNODE() works on Wikidata even with hint:Query hint:optimizer "None" (that's why).

As for UUID() and STRUUID(), it seems that there is no significant performance difference, so you can use any of them.

Please note that both browser and server cache results, hence, add a few spaces or commented current time to every query.

Update

With a single triple pattern, one can use the sample service.

Upvotes: 3

Related Questions