I am trying to get all the city names of all countries in the world using this below query. Whenever I execute this below query it returns this message "Query timeout limit reached".

Is there any other way to get all the data before it reaches timeout limit?

SELECT ?country ?countryLabel ?city ?cityLabel
  ?city wdt:P31/wdt:P279* wd:Q515;
        wdt:P17 ?country .

  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
ORDER BY ?country

1 Answer 1


Based on my comment, take out the ORDER BY.

Why? It has probably to do with the query optimizer, but I don't have any real explanation. In general, with SQL that I'm more familiar, ORDER BY when unnecessary is the first thing to take out when improving query performance.

(Note that this question was cross-posted at StackOverflow, and there is a longer discussion there.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.