{"id":346,"date":"2020-01-14T16:37:24","date_gmt":"2020-01-14T16:37:24","guid":{"rendered":"http:\/\/wikidata.wwwnlsrc4.supercp.com\/?page_id=346"},"modified":"2020-11-17T12:47:23","modified_gmt":"2020-11-17T12:47:23","slug":"query-with-more-than-one-variable","status":"publish","type":"post","link":"https:\/\/wdqs-tutorial.toolforge.org\/index.php\/simple-queries\/adding-variables\/query-with-more-than-one-variable\/","title":{"rendered":"Query with more than one variable"},"content":{"rendered":"\n<h2> Queries with more than one variable <\/h2>\n\n\n\n<p> Until now our queries essentially had just one variable, even if additional variables were declared for the label and\/or description of the item. Now we will look at queries with more variables. <br>The following query retrieves items that are part of the Star Wars film series, and the director of each film.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror cm-s-eclipse\" data-setting=\"{&quot;mode&quot;:&quot;sparql&quot;,&quot;mime&quot;:&quot;application\/sparql-query&quot;,&quot;theme&quot;:&quot;eclipse&quot;,&quot;lineNumbers&quot;:true,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true}\">#Star Wars films\n\nSELECT ?item  ?itemLabel ?director\nWHERE \n{ \n  ?item wdt:P179 wd:Q22092344. # item is part of the series Star Wars (film series)\n  ?item wdt:P57 ?director.     # item\u2019s director property\u2019s value is collected by the director variable\n  SERVICE wikibase:label { bd:serviceParam wikibase:language &quot;[AUTO_LANGUAGE]&quot;. }\n}<\/pre><\/div>\n\n\n\n<h3>Query explanation<\/h3>\n\n\n\n<p>In the SELECT section we have the variables ?item and ?director, as well as ?itemLabel which retrieves the label for ?item.<\/p>\n\n\n\n<p>In the WHERE section, on lines 6 and 7, we see the pattern matching conditions:<br>?item wdt:P179 wd:Q22092344.<br>?item wdt:P57 ?director. <br> <br> SPARQL seeks Wikidata items with statements that match the pattern defined in the WHERE section. So, as before, our WHERE section&#8217;s first line says, &#8220;Find me items that have a statement with a P179 property (part of a series) with the value Q22092344 (Star Wars (film series))&#8221;. <br>The second line says, &#8220;Then for each of those items, find me their P57 property (director) and put its value in the variable ?director.&#8221; <br><a href=\"https:\/\/wdqs-tutorial.toolforge.org\/index.php\/simple-queries\/adding-match-patterns\/two-or-more-match-patterns\/\">As we&#8217;ve seen<\/a>, there is an implicit AND between each statement in the WHERE section, i.e. only patterns that match\u00a0<strong>all<\/strong>\u00a0statements will be returned by this query.\u00a0 <\/p>\n\n\n\n<p>Now let&#8217;s run the query:<\/p>\n\n\n\n<iframe class=\"\" src=\"https:\/\/query.wikidata.org\/#%23Star%20Wars%20films%0A%0ASELECT%20%3Fitem%20%20%3FitemLabel%20%3Fdirector%0AWHERE%20%0A%7B%20%0A%20%20%3Fitem%20wdt%3AP179%20wd%3AQ22092344.%20%23%20item%20is%20part%20of%20the%20series%20Star%20Wars%20%28film%20series%29%0A%20%20%3Fitem%20wdt%3AP57%20%3Fdirector.%20%20%20%20%20%23%20item%E2%80%99s%20director%20property%E2%80%99s%20value%20is%20collected%20by%20the%20director%20variable%0A%20%20SERVICE%20wikibase%3Alabel%20%7B%20bd%3AserviceParam%20wikibase%3Alanguage%20%22%5BAUTO_LANGUAGE%5D%22.%20%7D%0A%7D\" style=\"width:100%;max-width:100%;height:450px\" frameborder=\"0\"><\/iframe>\n\n\n\n<h4><strong>What needs to be added to see the names of the directors? Add it and run the query again.<\/strong><\/h4>\n\n\n\n<div class=\"wp-block-coblocks-accordion\">\n<div class=\"wp-block-coblocks-accordion-item\"><details><summary class=\"wp-block-coblocks-accordion-item__title\">Show solution<\/summary><div class=\"wp-block-coblocks-accordion-item__content\">\n<iframe class=\"\" src=\"https:\/\/query.wikidata.org\/#%23Star%20Wars%20films%0A%0ASELECT%20%3Fitem%20%20%3FitemLabel%20%3Fdirector%20%3FdirectorLabel%0AWHERE%20%0A%7B%20%0A%20%20%3Fitem%20wdt%3AP179%20wd%3AQ22092344.%20%23%20item%20is%20part%20of%20the%20series%20Star%20Wars%20%28film%20series%29%0A%20%20%3Fitem%20wdt%3AP57%20%3Fdirector.%20%20%20%20%20%23%20item%E2%80%99s%20director%20property%E2%80%99s%20value%20is%20collected%20by%20the%20director%20variable%0A%20%20SERVICE%20wikibase%3Alabel%20%7B%20bd%3AserviceParam%20wikibase%3Alanguage%20%22%5BAUTO_LANGUAGE%5D%22.%20%7D%0A%7D\" style=\"width:100%;max-width:100%;height:450px\" frameborder=\"0\"><\/iframe>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p> # A little bit of syntax<\/p>\n\n\n\n<p> If we wanted the query to show the name of each director, but not the Q number, we could omit the ?director from the SELECT section and only declare ?directorLabel. This implies there is a ?director variable (which we see in the WHERE section) but it isn\u2019t presented in the query results.<\/p>\n\n\n\n<p> <\/p>\n\n\n\n<p><\/p>\n\n\n\n<iframe class=\"\" src=\"https:\/\/query.wikidata.org\/#%23Star%20Wars%20films%0A%0ASELECT%20%3Fitem%20%20%3FitemLabel%20%3FdirectorLabel%0AWHERE%20%0A%7B%20%0A%20%20%3Fitem%20wdt%3AP179%20wd%3AQ22092344.%20%23%20item%20is%20part%20of%20the%20series%20Star%20Wars%20%28film%20series%29%0A%20%20%3Fitem%20wdt%3AP57%20%3Fdirector.%20%20%20%20%20%23%20item%E2%80%99s%20director%20property%E2%80%99s%20value%20is%20collected%20by%20the%20director%20variable%0A%20%20SERVICE%20wikibase%3Alabel%20%7B%20bd%3AserviceParam%20wikibase%3Alanguage%20%22%5BAUTO_LANGUAGE%5D%22.%20%7D%0A%7D\" style=\"width:100%;max-width:100%;height:450px\" frameborder=\"0\"><\/iframe>\n<\/div><\/details><\/div>\n<\/div>\n\n\n\n<div class=\"wp-block-coblocks-accordion\">\n<div class=\"wp-block-coblocks-accordion-item\"><\/div>\n<\/div>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Queries with more than one variable Until now our queries essentially had just one variable, even if additional variables were declared for the label and\/or description of the item. Now we will look at queries with more variables. The following query retrieves items that are part of the Star Wars film series, and the director [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":""},"categories":[11],"tags":[],"_links":{"self":[{"href":"https:\/\/wdqs-tutorial.toolforge.org\/index.php\/wp-json\/wp\/v2\/posts\/346"}],"collection":[{"href":"https:\/\/wdqs-tutorial.toolforge.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wdqs-tutorial.toolforge.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wdqs-tutorial.toolforge.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wdqs-tutorial.toolforge.org\/index.php\/wp-json\/wp\/v2\/comments?post=346"}],"version-history":[{"count":46,"href":"https:\/\/wdqs-tutorial.toolforge.org\/index.php\/wp-json\/wp\/v2\/posts\/346\/revisions"}],"predecessor-version":[{"id":2584,"href":"https:\/\/wdqs-tutorial.toolforge.org\/index.php\/wp-json\/wp\/v2\/posts\/346\/revisions\/2584"}],"wp:attachment":[{"href":"https:\/\/wdqs-tutorial.toolforge.org\/index.php\/wp-json\/wp\/v2\/media?parent=346"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wdqs-tutorial.toolforge.org\/index.php\/wp-json\/wp\/v2\/categories?post=346"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wdqs-tutorial.toolforge.org\/index.php\/wp-json\/wp\/v2\/tags?post=346"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}