Wikidata:SPARQL query service/A gentle introduction to the Wikidata Query Service/uk

Outdated translations are marked like this.

Other languages:
Afrikaans • ‎Bahasa Indonesia • ‎Deutsch • ‎English • ‎Türkçe • ‎català • ‎español • ‎français • ‎italiano • ‎polski • ‎português do Brasil • ‎svenska • ‎русский • ‎српски / srpski • ‎українська • ‎العربية • ‎বাংলা • ‎中文 • ‎日本語

М'який вступ до Wikidata Query Service

Have you ever wondered about questions like these?

  • What are the largest cities in the world that have a female mayor?
  • What airports are located within 100km of Berlin?
  • Who were all known descendants of Genghis Khan?

Wikidata has the answers.

Що таке Вікідані?

Wikidata is a repository of knowledge. You can read an introduction to the idea and concepts behind Wikidata on our introduction page.

Як задати питання?

The query language used to ask questions like that on Wikidata is called SPARQL. If this sounds too technical and overly complicated for you, don't worry. For this gentle introduction you won't have to learn SPARQL. Instead, we will look at existing example queries and how to edit them.

Що таке запит?

A query is a special form of question that computer systems can understand and answer. Unless you are interacting with an Artificial Intelligence, you would need to learn how to formulate your questions in a certain way.

Чи можу я вільно використовувати ці дані?

Oh yes. Wikidata can be used by anyone for everything because all data is in the Public Domain (CC0).

Що тепер?

We'll start with a simple example to show you how to use this service, and as we build up to more elaborate examples, you’ll get the answer to the fundamental question. Promise.

Як використовувати Вікідані для простого запиту

Пройдімо простий приклад демонстрації того, як отримати список всіх відомих котів у світі.

Отримати список усіх котів у світі

Використовуйте цю URL-адресу, щоб перейти до Query Service:

  1. Натисніть Приклади
  2. Виберіть Коти зі списку, що з'явиться у новому вікні
  3. Натисніть кнопку "Виконати запит" під полем коду


Це дало нам список всіх знаменитих і невідомих котів в Інтернеті – або, принаймні, тих, про яких повідомляє Вікіпедія. Це чудово, якщо ви любитель котів, а не, скажімо, собак.

Як щодо собак?

Якщо ви хочете, натомість, отримати список собак (або щось інше, раз на те пішло), існує два способи редагування запиту:

  1. Використовуйте Query Helper, щоб змінити елемент з кота на звіринець:  
  2. Редагувати вручну запит. Кожен елемент у Вікіданих однозначно ідентифікується за допомогою коду. Для "кіт свійський" цей код Q146. Щоб знайти відповідний код для "пес свійський", ви можете пошукати його на Вікіданих:
  1. Use autocompletion (will be covered at the end)
  2. Start with "Cat" example, remove "Q146"
  3. Place cursor after "wd:"
  4. Type "Dog" after "wd:"
  5. Press Ctrl+Space
  6. Use up/down arrows; when you hit Enter - it will be substituted with Q144
    Note: search results depend on interface language.
  1. Go to
  2. Type “dog” in the search box
  3. Click on the first result from the drop-down menu
  4. Take note of the item number for “dog” from the Wikidata page that opens (Q144)


Щоб змінити ваш запит з "котів" на "собак", просто замініть Q146 на Q144 у редакторі запиту SPARQL.

Run the program, and you will be presented with a list of all the famous and infamous dogs on the Internet.


Розбір запиту

Now let’s analyse the code to generalise this so we can search for any single object (for example, dogs, planets, countries, songs):

SELECT ?item ?itemLabel
	?item wdt:P31 wd:Q146 . 
	SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
  • SELECT A query SELECTs something. What exactly you want to select and display is described later, but for the time being you just state the placeholders (or variables). Here they are called ?item and ?itemLabel. You can tell that something is a variable if it starts with a question mark.
  • ?item This is the list of items we are looking for. In our case that would be the famous cats. Items on Wikidata work in many different languages, almost 300 of them. Because we don’t think that everything in the world is English and all the other languages are just special cases of English, items are stored in a way that works across languages. Every concept gets a number. Q146 is the concept of a cat, Q64 is Berlin in Germany, Q42 is the writer Douglas Adams and so on. Tip: ?item is just a variable name that we decided to use in our query. It could be anything, for example: ?animal.
  • ?itemLabel Humans can digest names in a human language much better than numbers. A label is the name of an item in a human language, e.g. English (or Esperanto, or Japanese, or Zulu…). We want the labels displayed in our query so that Q1371145 gets displayed as “Socks” (the cat belonging to Bill Clinton and family). Precise details about label service in User manual.
  • WHERE {   This is the WHERE clause of the query. Here we define what goes in the placeholders. A WHERE clause starts with an opening curly bracket { and ends with a closing curly bracket }.
  • wdt:P31 This is the predicate of the subject. If you hover over it, you’ll see that it stands for instance of.


  • wd:Q146 . This is the object. If you hover over it, you’ll see that it stands for cat.


All this is quite a mouthful. It may help to express the query in natural language:

“Give me a list of items and their labels, where the items are instances of cat. Then generate the labels to the items in English.”

With the code we used in our examples we showed you a list of all the famous and infamous cats on the Internet. This query can easily be changed to show a similar list for dogs, for example.

Від тексту до SPARQL покроково

Ці зображення показують, як писати триплети людською мовою, і перетворювати їх у запити SPARQL:

The key is to prefix variables with ?, items with wd: and properties with wdt:, and then using the Ctrl+Space (or Ctrl+Alt+Space or Alt+Enter) keyboard shortcut to activate the auto-completion feature that replaces the latter two with the actual Wikidata identifiers.



Занурення в інтерфейс користувача

Як змінити мову, якою відображаються результати?

Завдяки цьому інструменту пошукових запитів ви можете не тільки налаштовувати й шукати прості або агреговані, складені, вкладені та комплексні запити, але ви також можете шукати будь-якою мовою й отримувати результати також будь-якою мовою.

  • Змініть код мови за умовчанням з "en" (англійська мова) на будь-який інший код мови, скажімо "uk" для української.
SELECT ?item ?itemLabel WHERE
     ?item wdt:P31 wd:Q146 .
     SERVICE wikibase:label { bd:serviceParam wikibase:language "ja" }

Як змінити порядок сортування відображуваних результатів?

The order of the items displayed can be easily changed in the interface. Just click on the relevant columns of the search results to customise the sorting order:


Як змінити мову інтерфейсу?

Клацніть слово English та виберіть мову зі списку, що відображається:


Зверніть увагу, інтерфейс користувача змінився на обрану мову:

Але я хочу фото котів! Як шукати зображення?

Досі ми бачили результати запитів, що відображаються у вигляді таблиці. Спробуймо кілька зображень:

Натисніть кнопку "Приклади" й виберіть приклад "Ще більше котів (із зображеннями)". Запустіть запит, і зображення котів повинні появитися в нижній частині екрана.#


This is what displays the result as images instead of a table. You can manually switch how the data is displayed by using the “Display” menu in the lower right corner of the result. Try switching the menu to “Table” to see the same result in a table view.

Let’s have a look at what’s new in the query, compared to the query in the previous chapter. Written in plain English, the query would read “Give me all items that have something to do with cats. Also give me the image for each item. And by the way, display the result as a grid of images, not as a table.”

  • #defaultView:ImageGrid What looks like a comment, is actually an instruction to display the query result as images instead of a table.
  • ?x1 This means that we query for any predicate, not only for “is an instance of”. Think of predicates like “depicts” (P180) or “is named after” (P138). We are not using ?x1 anywhere else in the query, meaning the placeholder stands for “I don’t care what the predicate is, give me all results that somehow have a cat as the subject”
  • OPTIONAL Inside the curly braces you see another statement that adds optional data to the result. The placeholder ?item is reused and coupled with the predicate P18 (meaning “(has) image” and a new placeholder ?pic. Wrapping the statement with OPTIONAL means that items do not necessarily have to have a P18 predicate to show up in the list and that the ?pic placeholder can be empty.

Try modifying the query:

  • Search for dogs instead of cats. Hint: Change the Object part of the first statement in WHERE.
  • Only show items that “depict” cats (you’ll get paintings). Hint: replace ?x1 with something else.
  • Remove the OPTIONAL

There are other ways to show your data, but not all of them are always applicable, which is why some are greyed out in the menu. “Image map” is only selectable if the result data actually contains image URLs. In one of the following chapters you’ll learn how to display items as points on a map.

Як поділитися вашим запитом для використання іншими?

If you want to share your query with someone else – say, on social media – you can create a short link for your query.

  • Complete your query
  • Click the LINK icon:
  • Copy the URL listed there. This is the URL for the query.

Пошук речей на картах

There are more ways to visualize the query results. If the query asks for geocoordinates, the results can be displayed on a map.

Look at this example of lighthouses in Norway. When you run the query, you’ll see red dots that mark the location of lighthouses on the Norwegian coast.

Using the Explorer Dialog

Once the results of a query have loaded, you can see a magnifying glass icon on each result. Clicking this icon opens the Explorer Dialog.


The explorer dialog by default, displays a single node representing that particular result. Below the node, you can see a toggle that defaults to ‘Outgoing’. This means that clicking on any node will expand all the properties of that node, from the entire Wikidata knowledge base. Toggling this to ‘Incoming’ allows you to see all the incoming links or properties that point to the node. This is a way to explore all the relationships between the various items and their properties using Wikidata.


You can open multiple explorer dialogs at once, allowing you to compare the results of more than one query at once. The explorer dialog also has a toolbar at the bottom right corner which is used to switch between multiple views like Graph, Tree, Map, Table etc.

Ось ще більше

There are more visualizations for you to explore:

Look through the query examples and try them out!


In the editor, you can press Ctrl+Space at any point in the query and get suggestions for code that might be appropriate; select the right suggestion with the up/down arrow keys, and press Enter to select it.

For example, instead of writing out SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } every time, you can just type SERV, hit Ctrl+Space, and the first suggestion will be that complete label service incantation, ready for use! Just hit Enter to accept it. (The formatting will be a bit different, but that doesn’t matter.)

And autocompletion can also search for you. If you type one of the Wikidata prefixes, like wd: or wdt:, and then just write text afterwards, Ctrl+Space will search for that text on Wikidata and suggest results. wd: searches for items, wdt: for properties. For example, instead of looking up the items for Johann Sebastian Bach (Q1339) and father (P22), you can just type wd:Bach and wdt:fath and then just select the right entry from the autocompletion. (This even works with spaces in the text, e. g. wd:Johann Sebastian Bach.)

NB: For ChromeOS and MacOS users: the shortcuts Ctrl+Alt+Space and Alt+Enter should also work.

Куди перейти звідси

You can probably find your way around the Wikidata Query Service now. Exploring the interface and changing values in the queries can be a good way to learn how to ask your own questions on Wikidata.