SandboxQuery
This sample page with semantic queries shows if and how a sort parameter affects the output of an inline query. If you sort by a "wrong" property, than the result set is changed. See [1] and [2].
Query all pages in category
This query finds all pages in the category, even if one of the pages does not contain a property from the given columns.
{{#ask: [[Category:Testing]] |?Has property A=Property A |?Has property B=Property B |offset=0 |limit=30 |format=table |mainlabel=Page |order=ASC }}
Page | Property A | Property B |
---|---|---|
SandboxA | A1 | B1 |
SandboxB | A2 | |
SandboxC | A3 | B3 |
Query all pages in category sorted by property A
This query returns all pages in the category sorted by property A. Since page SandboxA, SandboxB and SandboxC do contain the property A, all of them are returned.
{{#ask: [[Category:Testing]] |?Has property A=Property A |?Has property B=Property B |offset=0 |limit=30 |format=table |mainlabel=Page |sort=Has property A |order=ASC }}
Page | Property A | Property B |
---|---|---|
SandboxA | A1 | B1 |
SandboxB | A2 | |
SandboxC | A3 | B3 |
Query all pages in category sorted by property B
But the main goal is to explicitly sort by property B. All pages in the category shall be found in the same way as before, even pages having property B not set.
But since page SandboxB does not contain the property B, it is not in the result.
{{#ask: [[Category:Testing]] |?Has property A=Property A |?Has property B=Property B |offset=0 |limit=30 |format=table |mainlabel=Page |sort=Has property B |order=ASC }}
Page | Property A | Property B |
---|---|---|
SandboxA | A1 | B1 |
SandboxC | A3 | B3 |
Set property within the ask condition
Setting the property B within the ask condition even just return pages with this property set:
{{#ask: [[Category:Testing]][[Has property B::+]] |?Has property A=Property A |?Has property B=Property B |offset=0 |limit=30 |format=table |mainlabel=Page |sort=Has property B |order=ASC }}
Page | Property A | Property B |
---|---|---|
SandboxA | A1 | B1 |
SandboxC | A3 | B3 |
Well, just removing the sort does not change the result set:
{{#ask: [[Category:Testing]][[Has property B::+]] |?Has property A=Property A |?Has property B=Property B |offset=0 |limit=30 |format=table |mainlabel=Page }}
Page | Property A | Property B |
---|---|---|
SandboxA | A1 | B1 |
SandboxC | A3 | B3 |
Some variations
Another try:
{{#ask: [[Category:Testing]][[Has property A::+]] |?Has property A=Property A |?Has property B=Property B |offset=0 |limit=30 |format=table |mainlabel=Page |sort=Has property B |order=ASC }}
Page | Property A | Property B |
---|---|---|
SandboxA | A1 | B1 |
SandboxC | A3 | B3 |
Another try:
{{#ask: [[Category:Testing]][[Has property B::+]] |?Has property A=Property A |?Has property B=Property B |offset=0 |limit=30 |format=table |mainlabel=Page |sort=Has property B,Has property A |order=ASC,ASC }}
Page | Property A | Property B |
---|---|---|
SandboxA | A1 | B1 |
SandboxC | A3 | B3 |
Another try:
{{#ask: [[Category:Testing]][[Has property B::+]] |?Has property A=Property A |?Has property B=Property B |offset=0 |limit=30 |format=table |mainlabel=Page |sort=Has property A,Has property B |order=ASC,ASC }}
Page | Property A | Property B |
---|---|---|
SandboxA | A1 | B1 |
SandboxC | A3 | B3 |
Conclusion
Never use a property as sort value, which is not set on all pages you want to return. When using a form make those fields mandatory you want to sort by later.