How to return only unique rows using the Google Sheets Query function?

The Google Sheets Query function can be used to return only unique rows in a sheet by using the distinct keyword. This keyword will return only the unique values from the specified column or range of columns, eliminating any duplicate values. This can be useful for finding and removing duplicates in a dataset or for returning only unique values to another sheet.


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.

The following tutorials explain how to perform other common operations in Google Sheets:

x