5.3 C
London
Thursday, December 19, 2024
HomeSoftware TutorialsGoogle SheetsGoogle Sheets Query: How to Return Only Unique Rows

Google Sheets Query: How to Return Only Unique Rows

Related stories

Learn About Opening an Automobile Repair Shop in India

Starting a car repair shop is quite a good...

Unlocking the Power: Embracing the Benefits of Tax-Free Investing

  Unlocking the Power: Embracing the Benefits of Tax-Free Investing For...

Income Splitting in Canada for 2023

  Income Splitting in Canada for 2023 The federal government’s expanded...

Can I Deduct Home Office Expenses on my Tax Return 2023?

Can I Deduct Home Office Expenses on my Tax...

Canadian Tax – Personal Tax Deadline 2022

  Canadian Tax – Personal Tax Deadline 2022 Resources and Tools...

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

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

How to Use COUNTIF with Multiple Ranges in Google Sheets
How to Use SUMIF with Multiple Columns in Google Sheets
How to Sum Across Multiple Sheets in Google Sheets

Subscribe

- Never miss a story with notifications

- Gain full access to our premium content

- Browse free from up to 5 devices at once

Latest stories