User:TweetsFactsAndQueries/Queries/UN member states

A list of UN member states is a useful component of a number of queries, but annoyingly complicated to get. For convenience, here it is on its own, so that I can just copy+paste it in the future.

SELECT DISTINCT ?state WHERE {
  ?state wdt:P31/wdt:P279* wd:Q3624078;
         p:P463 ?memberOfStatement.
  ?memberOfStatement a wikibase:BestRank;
                     ps:P463 wd:Q1065.
  MINUS { ?memberOfStatement pq:P582 ?endTime. }
  MINUS { ?state wdt:P576|wdt:P582 ?end. }
}
Try it!

Variant for use in query templates:

SELECT DISTINCT ?id WHERE { ?id wdt:P31/wdt:P279* wd:Q3624078; p:P463 ?memberOfStatement. ?memberOfStatement a wikibase:BestRank; ps:P463 wd:Q1065. MINUS { ?memberOfStatement pq:P582 ?endTime. } MINUS { ?id wdt:P576|wdt:P582 ?end. } }
Try it!

To use this query in another query on-wiki, you can transclude it like this:

SELECT … WITH {
  {{User:TweetsFactsAndQueries/Queries/UN member states|style=query|  }}
} AS …

The optional last (positional) parameter specifies an indentation to use (here, two spaces, appropriate for a named subquery).

Note that the initial line must be indented at the transclusion site (hence the two leading spaces in the example).