Table of Contents
The Google Sheets Query function is a powerful tool that allows users to retrieve specific data from a larger dataset. One useful application of this function is to return only unique rows from a dataset. This can be achieved by using the “SELECT DISTINCT” statement within the query formula. By specifying the columns to be selected and adding the “DISTINCT” keyword, the query will only return rows with unique values in those columns, eliminating any duplicates. This allows for a more streamlined and organized display of data, making it easier to analyze and manipulate.
Google Sheets Query: Return Only Unique Rows
You can use the following basic syntax to return only unique rows when performing a query in Google Sheets:
=UNIQUE(QUERY(A1:B16, "SELECT A, B"))
By wrapping the UNIQUE() function around the QUERY() function, we can return only the unique rows from the query.
The following examples show how to use this syntax in practice.
Example: Return Unique Rows in Google Sheets Query
Suppose we have the following dataset that contains information for 15 basketball players:

We can use the following formula to perform a query that returns only the unique combinations of Team and Position:
=UNIQUE(QUERY(A1:B16, "SELECT A, B"))
The following screenshot shows how to use this formula in practice:

Notice that the query only returns unique combinations of Team and Position.
For example, there are three rows where Team is equal to “A” and Position is equal to “Guard” but only one of these rows is returned in our query.
We can also wrap the UNIQUE() function around more advanced queries.
For example, we could use the following query to return only unique rows where the team is equal to A or B:
=UNIQUE(QUERY(A1:B16, "SELECT A, B WHERE A='A' OR A='B'"))
The following screenshot shows how to use this formula in practice:

Once again, the query only returns unique rows.
Additional Resources
Cite this article
stats writer (2024). How can I use the Google Sheets Query function to return only unique rows from my data?. PSYCHOLOGICAL SCALES. Retrieved from https://scales.arabpsychology.com/stats/how-can-i-use-the-google-sheets-query-function-to-return-only-unique-rows-from-my-data/
stats writer. "How can I use the Google Sheets Query function to return only unique rows from my data?." PSYCHOLOGICAL SCALES, 1 Jul. 2024, https://scales.arabpsychology.com/stats/how-can-i-use-the-google-sheets-query-function-to-return-only-unique-rows-from-my-data/.
stats writer. "How can I use the Google Sheets Query function to return only unique rows from my data?." PSYCHOLOGICAL SCALES, 2024. https://scales.arabpsychology.com/stats/how-can-i-use-the-google-sheets-query-function-to-return-only-unique-rows-from-my-data/.
stats writer (2024) 'How can I use the Google Sheets Query function to return only unique rows from my data?', PSYCHOLOGICAL SCALES. Available at: https://scales.arabpsychology.com/stats/how-can-i-use-the-google-sheets-query-function-to-return-only-unique-rows-from-my-data/.
[1] stats writer, "How can I use the Google Sheets Query function to return only unique rows from my data?," PSYCHOLOGICAL SCALES, vol. X, no. Y, ص Z-Z, July, 2024.
stats writer. How can I use the Google Sheets Query function to return only unique rows from my data?. PSYCHOLOGICAL SCALES. 2024;vol(issue):pages.
