Help talk:Inline queries/Archive

Jump to: navigation, search

Bug in Sort Table

When the tables are sorted it seems that the sorting is the wrong way round. In particular when the user clicks on the arrow at the top and it points up,
i.e. somethings like /\, it is narrow at the top and thick at the bottom, so the table should be sorted with the big at the bottom, small at the top. That is what happens in the regular sort table, see: [1]
However when I call #ask and use format=table, I find that the arrow is the wrong way round.
Philip Kinlen 15:11, 11 November 2008 (UTC)

Don't want the column heading to be a link

Suppose I have a table which is produced as a result of a call to #ask,
then how can I ensure that the column heading for a particular property is not displayed as a link?
Currently the column headings for properties are displayed as links by default and using link=none does not affect the column heading. For example see how the Price, Currency and Location column headings are links in the following example table.
Philip Kinlen 14:37, 30 October 2008 (UTC)

To fix this, you could always use a layout template to generate tabular output. Its a messy fix for such a simple problem, but I describe it in detail here:

Alternatively, if you have the latest version of SMW installed you can use the parameter headers. i.e. headers=plain : show labels and headers, but a plain text without links (available since SMW 1.4.3).

The results formatting side of ask is very messy IMHO.

--Dan Bolser 07:14, 4 September 2009 (UTC)

Want to change back-ground color of the column heading

Is it possible to change the background color in the column header. For example see how in the example table it is light blue. In the documentation I didn't see it mentioned how to set the back-ground color.
I tried

| style=background:red


| background=red

but neither seemed to work.
I wonder can we use format=template to create a sortable table? I can see who we could template each row and make the whole thing look like a table, but then it wouldn't be sortable. Philip Kinlen 17:05, 31 October 2008 (UTC)

It should be sortable if you set 'class="sorttable'. For more info, see:

--Dan Bolser 07:15, 4 September 2009 (UTC)

Possible bug when using searchlabel

It seems that when we use

limit=0 | searchlabel=Click to browse a list of cities

the table that is produced is missing some of the details, for example the mainlable parameter seems to be ignored and so are link=subject and the intro.
Also, for some reason I'm getting the numeric data in one column repeated, see example table in particular the price column, instead of getting 40, I'm getting 4040.

And something that would be very very useful would be to be enable users to generate queries using forms. The edit query window is not user friendly enough, for example users shouldn't need to know what a Category is. Something like the this has a nicer user-interface, though it is not quite working.
Philip Kinlen 09:40, 1 November 2008 (UTC)

Sort by X and then pagename?

The default sort order of an ask query seems to be alphabetical by pagename. However, if you sort by some property X, the resulting order (after sorting by X) seems to be ... Wait ... is the default sort order pagename? How do I sort by page name?

My question is, how do I sort by X and then pagename?

--Dan Bolser 07:19, 4 September 2009 (UTC)

Does anybody has an idea please???

--Eva 09:49, 21 August 2010 (UTC)
I've found the answer " format:category" --Eva 09:00, 23 August 2010 (UTC)

Meta properties

Is it posible to select meta properties from pages in quries? It would be wery lelpfull. For example - last revision date, so I can sort selection by this property. The query may be looks like this:

  [[Population::+]] [[Category:City]]
  | ?Population
  | link=all | limit=10 | sort=Population | order=desc

-- 21:30, 8 February 2010 (UTC)

Hi, the last revision date is available via the magic words described here. We use it e.g. on the start page of our website ( for sorting the news. A sample annotation would look like this:

P.s. Please note that the SMW user mailing list is the perfect place for getting quick response to this type of questions. ;)

--Phiza, 9 February 2010

So I must provide each page in my wiki with property [[Last changed::{{REVISIONYEAR}}-{{REVISIONMONTH}}-{{REVISIONDAY2}}|]]. That is not a good idea. The better way is provide #ask function with special sintax to specify in select clause meta properties like revision date.

-- 19:51, 9 February 2010 (UTC)

Help converting an old ASK query

Just finished a server and version change at my site. If someone could show me how to convert the following old ASK table, I'm a fairly quick learner, following your example.

<ASK Mainlabel="Philosophers who flourished around the thirteenth century" Header="show" Link="all" sort="Flourished" order="ascending"> [[Category:Philosophers]] [[Flourished:=>1240]] [[Flourished:=<1330]] [[Birth Date:=*|Born]] [[Flourished:=*|Fl.]] [[Death Date:=*|Died]] [[Birth Country Name:=*]] [[Bcmp Pages:=*]] </ASK>

Thanks in advance, to whomever will show me the way on this. (We can discuss a PayPal gratuity for your help, perhaps.) -- Thekohser 03:21, 21 April 2010 (UTC)

Or, to put it another way, could someone add a section on the Help page to show how one would display only the German cities with a population between 500,000 and 749,999? -- Thekohser 10:42, 21 April 2010 (UTC)

Usage of the COUNT-format combined with other information

I have a category named "project". Within this category there are several named projects like "proj_A" and "proj_B". Now there are pages with the attribute "project_name" set to "proj_A" or "proj_B"

  • list of all my projects: {{#ask: [[Category:project]] | ? | format=ul}}
  • list of members of a special project: {{#ask: [[project_name::proj_A]] | ? | format=ul}}

Now I'd like to have a query, which gives me the list of all my projects directly combined with the amount of pages. This means: For each returned row of the query I ask for the count of pages with the right attribute.

This seems halfway to work this the help of a template like: {{{1}}} {{#ask: [[project_name::{{{1}}}]] | format=count}}. I get the correct result, but there are always error-messages from smw: "Der Teil „]]“ der Anfrage wurde nicht verstanden. Die Ergebnisse sind eventuell nicht wie erwartet."

Any advice? -- 06:55, 31 May 2010 (UTC)

I assume no one was ever able to fix this, but if so, I'd love this information. 13:37, 23 July 2011 (CEST)

Sorting multiple results for single Attribut

One Page has multiple entries for one attribute:

  • [[myattribute::isAlpha]]
  • [[myattribute::isDelta]]
  • [[myattribute::isBravo]]

So, if i ask for this page und let me show ?myattribute I get three results.

These are alphabetical ordered.

Do I have the possibility to sort the output in a different way? (not Alpha, Bravo, Delta - but Alpha, Delta, Bravo)?

-- 11:26, 1 June 2010 (UTC)

No - the only way you can do arbitrary sorting like that is through either the Record type or the Semantic Internal Objects extension. Yaron Koren 15:15, 1 June 2010 (UTC)

Supress auto-capitalize?

I'm trying to print out a URL, but the #ask query keeps capitalizing the h in http. I have a template that puts square brackets around the URL, but it always comes out like
[Http:// Example]
instead of a click-able link. Is there a formatting option I missed? Sxtynnmach1 20:11, 29 June 2010 (UTC)
Fixed it by using
--Sxtynnmach1 14:43, 30 June 2010 (UTC)

This is a little late, but I just ran into this same issue and it turned out to simply be that I had the wrong data type associated with the property. It should have been [[has type::URL]]. 00:25, 2 February 2012 (CET)

'order' parameter works without 'sort' parameter

The description of the 'order' parameter is wrong. It currently says

defines how results should be ordered, only applicable if sort is used, ascending is the default (see Help:Selecting pages) 

but it is also applicable when 'sort' is not used - it then applies to the pagename/mainlabel.

--Patrick Nagel 02:31, 13 July 2010 (UTC)

Table Format Repeats Numbers

When I have a query with format="table" and it returns a property of type "number", the number repeats inside the column, like 3.53.5 instead of just 3.5. Is there a fix for this?

Display Number of articles

Right now I have a Shoe brand page. I have used inline query to list all the brands. However, what I also want in the table is a title for "Number of Styles" and "Number of Shoes" which will be how many shoes and styles each brand has on the wiki. How do I do this.

Try using Property:Subcategory of. This should give you list of all pages and subcategories. At least in theory, since I'm still struggling to make use of that. --Deepskypedia 14:03, 8 April 2011 (CEST)

Update automatically an inline query?

I wonder if there is a way to automatically update an inline query.

My query is : {{#ask: [[User:+]]}} and i would like that whenever a new user is created that this request be updated when I go to this page. --Eva 09:55, 21 August 2010 (UTC) an idea ?

I have a similar problem. I need a way to update the query everytime a user hits refresh. Is this possible? --Tallith 00:32, 16 February 2011 (CET)

Ok, sorry, I found the answer. Just disabling the caching of the wiki. --Tallith

Setting Column width

Is there any way to control the width of the different columns? It would be particularly helpful if this was possible for columns containing images.--Gollum 19:13, 28 October 2010 (CEST)

Standard parameters for inline queries

This section really does not make much sense here, as it applies to all queries, and should probably be moved to a separate page. --Jeroen De Dauw 21:50, 13 February 2011 (CET)

Intro underscore not replaced any more

intro: this parameter specifies a text that should be prepended to the output of a query, but only if one or more results exist. In the above example, one could write 
{{#ask: ... | intro=Upcoming conferences:_}}
Note that we use «_» to encode the final space. This is needed for initial and final spaces in any parameter, since those are otherwise removed internally (this is always the case in MediaWiki and is not specific to SMW). 

For some time, the underscore "_" is not replaced any more but displayed as is on our wiki. I solved this by using <nowiki> tags and a regular space.

Right you are - I just fixed the documentation. 21:01, 8 March 2011 (CET)

White spaces

Do you know why {{#show:Spain|?population}} returns:


(without white spaces) but the next query:

 Spain ({{#show:Spain|?population}} people)


 Spain (_50.000.000_ people)

(where the _ are white spaces)?

It's a problem. When I list some countries the line breaks:

 * Spain ({{#show:Spain|?population}} people)

is shown in two lines.


-- 20:58, 8 March 2011 (CET)

Hidden categories in inline query results


Is there a way to prevent hidden categories from being displayed in inline queries?

Thanks! 19:04, 17 April 2011 (CEST)

Is there any way to run an #ask query from php?

Is there a reliable way to query the semantic database from within php so I can make logic decisions based on the result of a query? Apologies if this is a dumb question as I am both new to php, mySQL and mediawiki.

> of course, there is - that's the main benefit. search for SMW API functions, you can extend and run queries

pass parameters to template

If the output is set to template, is there a way to pass aditional parameters inside it? does pipe (|) or get (?param=value) work in this case? or any workaround?

Thats exactly my problem, too. I am using an ask-statement within a template. The template gets 3 parameter, 2 of them are used for the ask. The ask itself uses a template to generate the output, but i need the third parameter supplied to this template together with the results of the ask. Could anybody give me a hint how to do this? 17:28, 31 May 2011 (CEST)

Direct conditions on pages

returns the three pages User:A, User:B and User:C.

Is there an 'OR' syntax that works on categories.e.g

which would return page User:A, all pages in Category:cat1 and all pages in Category:cat2

Sorting Records

I have a record-attribute like

 [[President of::State;1990;1995]]

and a lot of Persons have this entry. Now I want to make a query of all Presidents of "State" sorted by from-date (which is 1990 in this case). I cannot get it to work - is it at all possible with Records?--VolkoV 14:03, 7 June 2011 (CEST)

Inline query from Semantic Toolbar?

When clicking on "Create" Inline Query in the Semantic Toolbar I get an open or save "index.php" dialog instead of the page. Anyone know how to fix this?


Mats-- 18:16, 16 June 2011 (CEST)

Searching for templates not for categories (solved)

I have a small wiki with 1.000 articles. The articles are not all categorized. And I use the same template (called Index) in nearly every articles. With this template I mark words in articles and then want to build Indexes with this keywords with the inline-query #ask.

Here you see some articles:

article 1:

some text - Template:Index::Germany - some text - some text - some text - some text - some text - some text - some text - some text - some text - some text - some text - some text - some text - Template:Index::USA - some text - some text - some text - some text - some text - some text - some text - some text - some text - some text - Template:Index::Great Britain

article 2:

Template:Index::Belgium - some text - some text - some text - some text - some text - some text - some text - some text - some text - some text - some text - some text - some text - some text - some text - some text - some text - some text - some text - some text - some text - some text - some text - some text - Template:Index::Germany

article 3:

some text - some text - some text - some text - some text - some text - Template:Index::Belgium - some text - some text - some text - some text - some text - some text - some text - some text - some text - some text - some text - some text - some text - some text - some text - some text - Template:Index::Australia - some text - some text -

I want to do something like:

{#ask: template=Index

but instead of template=Index a categoy ist expected.

The result of my inline-query should be:

article        Index
article 3      Australia
article 2      Belgium
article 3      Belgium
article 1      Germany
article 2      Germany
article 1      Great Britain
article 1      USA

What's to do? Jan -

I was wrong. Searching for templates is possible:
{#ask: [[Index::+]]
The answer I get is not wat I wanted. I get:
article        Index
article 1      Germany
               Great Britain
article 2      Belgium
article 3      Australia
... instead of:
article        keyword
article 3      Australia
article 2      Belgium
article 3      Belgium
article 1      Germany
article 2      Germany
article 1      Great Britain
article 1      USA
What's to do to get the wanted result?

Jan --

Use Semantic Internal Objects to store the data. Yaron Koren 15:29, 11 July 2011 (CEST)

Use property (template) more than once in an article

I would like to use a property more than once in an article. The properties should be capsuled in templates.

article ist "First chapter of my book"

some text - some text - some text - some text - some text - some text - some text - some text
 - some text - some text - some text - some text - some text - some text - some text - some 
text - some text - some text - some text - .....
{{Summary|keyword=Best practice|subject=Details of General Motors|importance=2|}}

some text - some text - some text - some text - some text - some text - some text - some text
 - some text - some text - some text - some text - some text - some text - some text - some 
text - some text - some text - some text - .....
{{Summary|keyword=Production |subject=Nice story from Peter|importance=4|}}

some text - some text - some text - some text - some text - some text - some text - some text
 - some text - some text - some text - some text - some text - some text - some text - some 
text - some text - some text - some text - .....
{{Summary|keyword=Finance|subject=Ford and BMW|importance=4|}}
Then I want to generate a List like this

keyword        | subject                   | importance
Best practice  | Details of General Motors | 2
Production     | Nice story from Peter     | 4
Finance        | Ford and BMW              | 4
and not a (for my needs) useless list like this: 

keyword:    Best practice, Production, Finance
subject:    Details of General Motors, Nice story from Peter, Ford and BMW
importance: 2, 4

I know, till now the articles are the items you use for the relations - but why not use the templates in the articles too? Yes I also know that DPL is able to do the job and I use it as a workaround - nevertheless I would be happy to do it all with SMW because SMW is great.

Is there an easy way to do this with "#ask"? Or what would you recommend?

Regards, Jan--

You use Semantic Internal Object for this. These Objects may reside on different pages (if you want) and can be queried.

I once created something for making Comments:

|Comment_content=some content

Afterwards i am able to query: e.g. all comments with Comment_Target="Hans Wurst"

{{#ask: [[comment_about::+]] [[Comment_target::Hans Wurst]] 
| ?Comment_source# 
| ?Comment_content# 

-- 20:31, 29 July 2011 (CEST)

introtemplate and outrotemplate are undocumented

The parameters for custom template formatting introtemplate and outrotemplate are undocumented, but mentioned here:

They're pretty much required if your custom template involves displaying data in a table.

Badon 05:21, 9 August 2011 (CEST)

There is some mention of it at Help:Template format, and they will be listed in the parameter table once this wikis SMW is updated.
This support costs you $9001; please provide the details I need to invoice you --Jeroen De Dauw 15:43, 9 August 2011 (CEST)

SMW Ask queries via the api

I'm struggling to work out how to do date related queries via the api. I'd like to code up something equivalent to

{{#ask:[[Has person:someuser]]  [[Has end date::>{{#time:d F Y H:i:s}}]]  }}

but I have no idea how to do the date comparison. This is what I have stabbed at so far:

$store = smwfGetStore();

$propertyValue = SMWPropertyValue::makeProperty('Has_person');
$wikiPage = SMWWikiPageValue::makePage('someuser', NS_USER);
$description = new SMWValueDescription($wikiPage);
$personDescription = new SMWSomeProperty($propertyValue, $description);

$date = date( 'd F Y H:i:s' );
$description = new SMWTimeValue( '_dat' );
$description->setUserValue( $date );
$propertyValue = SMWPropertyValue::makeProperty('Has_end_date');
$dateDescription = new SMWSomeProperty($property, $description);

// I don't know how I encode the comparison operator in [[Has end_date::>{{#time:d F Y H:i:s}}]]

$queryDescription = new SMWConjunction(array($personDescription,$dateDescription));

$query = new SMWQuery($queryDescription);

$printer = new SMWAutoResultPrinter('', SMWQueryProcessor::INLINE_QUERY);
$result = $printer->getResult($store->getQueryResult($query), array(), 1);

I used Yury Katkov programming examples page as a starting point (

Any help greatly appreciated

Adding a section on inverse property querying to this page

I just created an account to see if I could add the section myself, but no joy.

I just spent about 30 minutes and 8 google searches trying to discover how to make a "links here" query to do some fancy summing with SRF. Unfortunately, even when i did find the Help:Inverse Properties page, there was no example. At least, moving that documentation to this page as a new section would be exceedingly useful, as an inverse query is an extremely common operation, and it's not particularly well explained for SMW, at the moment.

Adding an example along with that documentation, would also be helpful.

Sticking with the City example, say that you have billions of person pages describing people that live in each city of the world. Each city page has a property "lives here" of type Page that lists each and every person that lives there. Your person pages each have their addresses as a single property, but they do not have a "lives in" property. (Because it often does not make sense to clutter your triples by making an inverse property for absolutely everything, and going back and adding a "lives in" property to every single individual that lives in the world would be unwise, at best).

You want to make a query add up the age for everyone living in a city. However, using a nested query or a template to do this will not work (because you cannot get the property of something that comes back from a query as a property, and using a template processes each result individually, so each result can't be summed). Instead, using the inverse query syntax of adding a "-" in front of the property in order to "make" the "lives in" property without having to modify each person page:

{{#ask: [[-lives here::CityName]]
 | ?age
 | format = sum

This query will bring back each person's page as a result, get their age, and (using format = sum is a Semantic Result Formats extension) add them all together to get a single number. All without having a property on the person's page to explicitly link them to that city.

Not saying you should use THIS example, but at least moving the inverse property documentation to this page will help out. I have actually been searching for this functionality for over a year, new it existed (because of the "links here" section on the "browse properties" pages), but didn't know how to make it work for myself in a query.

Thanks! Hamerst1 14:36, 17 August 2011 (CEST)

Placeholder for empty data for template purposes

Hi, all. I was wondering if there's a way to construct an ask query so that, when you're writing the results to a template, your template numbers don't get shifted if there's empty data. For example:


And in CarsTemplate:
Model: {{{1}}}
Color: {{{2}}}
MPG: {{{3}}}

Model: Porsche
Color: Red
MPG: 20mpg

But if a car is missing a "Model", what ends up happening is this:

Model: Red
Color: 20mpg
MPG: {{{3}}}

Is there a simple solution to this simple problem? Thanks. --Blicarea 19:47, 8 September 2011 (CEST)

Yeah, have a look at this page. Cheers --[[kgh]] 23:42, 8 September 2011 (CEST)
There's actually an even simpler solution - use "{{{3|}}}" instead of "{{{3}}}", etc. Yaron Koren 00:32, 9 September 2011 (CEST)
True, I should have thought of that right away. Why doing it the easy way if you can also do it in a complicated way? :( --[[kgh]] 01:32, 9 September 2011 (CEST)
Excellent! Thank you both! I knew there had to be an easy answer! In my code I have been alternating between "{{{3}}}" and "{{{3|}}}" for no good reason, because I didn't know what the pipe was for. Now I can go back and clean up everything :) Thanks again. --Blicarea 15:12, 9 September 2011 (CEST)

NOT for page-type pages?

If on a certain page, say page A, you need to create a list of other pages with the same value or values, it would make good sense to exclude page A from the query. However, I don't see if and how that's currently possible. Any ideas? Cavila 15:10, 24 November 2011 (CET)

I can't edit the article, so I'll post two possible workarounds on the talk page:
(1) Create a new property of type 'String' and make sure it gets its values from the page name (e.g. use PAGENAME or FULLPAGENAME in your template). In this way, you will be able to use the ! parameter for negation.
(2) Or choose format=template and exclude the results if the parameter for the page matches PAGENAME.
Cavila 17:02, 27 November 2011 (CET)
Heiya Cavila, this tip might be to specific to be added here. I will ask some other people for there opinion on this. However your tip is valuable and should be entered in the tip section of our SMW Community wiki anyway. Cheers --[[kgh]] 23:48, 27 November 2011 (CET)
Heiya Cavila, others agree with my option, but another intriguing appeared. As soon as you entered your tip there, I will add a link to it in an new section == Tips related to inline queries == :) How cool is this?! Cheers --[[kgh]] 21:44, 28 November 2011 (CET)
Thanks, Kghbln. I've added no tip anywhere but here, so it must have been someone else. But sure, a page or section for more complex approaches, be they workarounds to common problems or just advanced techniques, would be a good idea. Cavila 21:18, 29 November 2011 (CET)
I am glad you like this too. So far this tip was not added anythere. I wanted to encourage you to do so in the tip section of our SMW Community wiki. After this is done I will add the link. Cheers --[[kgh]] 23:40, 29 November 2011 (CET)
OK, I'll have a look as soon as I can find the time. Cavila 13:58, 30 November 2011 (CET)
See here. Feel free to correct me there or expand if I was unnecessarily brief. Cavila 12:02, 2 December 2011 (CET)
Great and thank you. I just included the like. Seem alright to me. :) Cheers --[[kgh]] 17:02, 2 December 2011 (CET)


I spotted a minor mistake or oversight here: Help:Inline queries#Introduction and default text. It says that nothing is printed when the query produces no results, but the introductory text is still printed in an inline query like:

{{#ask: [[SOMEPAGE]] |?property |intro=Results:  }}

(and likewise, if you use #show)

For instance:

{{#ask: [[Berlin]]
|?Location of
produces Results:
 Location of

Also default= has no effect in queries like the one above. The only solution I can think of would be to include [[Property name::+]] (here [[Location of::+]]), but seeing as it that would limit the pool of queryable pages, it would be unhelpful in more complex situations. Cavila 13:58, 30 November 2011 (CET)

The reason is that you are not looking for resulting pages but just for printouts. That's the reason why default= is not working. I think it would be a nice enhancement to get default working under such circumstances. I will add a note in the documentation. Cheers --[[kgh]] 17:18, 2 December 2011 (CET)

modification date

is there any way to display a list of recently changed articles?

Yes. Modification date is a Special property.
Example query:
  [[Modification date::+]]
  | ?Modification date
  | limit=10
  | sort=Modification date
  | order=descending
  | mainlabel=Page
PageModification date
"Modification date" is a predefined property that corresponds to the date of the last modification of a subject and is provided by Semantic MediaWiki.
Semantic MediaWiki 2.4.125 October 2016 20:50:50
Links in values25 October 2016 14:12:43
$smwgLinksInValues24 October 2016 21:16:56
Examples on working with the #set "separator" parameter24 October 2016 20:31:40
In-text annotation24 October 2016 20:25:44
Help:Setting values using #set24 October 2016 20:06:29
Lloyd Rutledge24 October 2016 10:16:39
Hans Oleander21 October 2016 09:55:12
Krabina Bernhard20 October 2016 13:19:14
A Generic Approach for Completing PDF-Forms with Data from Semantic MediaWiki20 October 2016 12:28:29
... further results
--Eric 12:13, 16 February 2012 (CET)

show vs ask

since show will be deprecated in newer version of SMW this statement from doc should be updated, need to add link=none: {{#ask: [[Berlin]] | ?population = }} otherwise it will be shown as a link {{#ask: [[Berlin]] | ?population = |link=none}} --Svdubl 19:46, 23 May 2012 (CEST)

Hi Svdubl, so far I have not heard about #show to be depreciated. However this does not mean that it might not be correct, since I do not subscribe to the dev-mailinlist. I would miss it a lot since I make very intensive use of #show on my wikis. Still you caught a superseded information in the current documentation which I just rectified. Thank you for this. #ask should use "mainlable=-" instead of "link=none" which would not work. Cheers --[[kgh]] 00:11, 24 May 2012 (CEST)
There are no threads on this page yet.