DISTINCT – showing unique results

Let’s have a look again at the query that lists all the works of art (Q838948) that take place in the Star Wars Universe.

If you run the query you will see that there are some duplicates in the results: certain items, like Q19590955 (Rogue One) and Q6074 (Star Wars Episode VII: The Force Awakens) appear more than once.
Query patterns often return duplicates – this can happen if, for example, you use the pattern “?item wdt:P31/wdt:P279* ?class”, and there are multiple paths from ?item to ?class: you will get a new result for each of those paths. For example, item Q19590955 (Rogue One) has both “film” and “3D film” as the values of P31, and each has a path to the “work of art” class, so the item shows up twice in the results.

To eliminate duplicates, we add the modifier DISTINCT after SELECT:

Skip to content