Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SELECT DISTINCT for only one Column in Google Sheets Query

Let's say I have the following query.

=query (A:C; "SELECT A, B, C")

How can I modify it so that it returns no duplicate A?

In other words, when several rows contain the same A, I want the results to include only one of those rows (the last one). Duplicates in other columns should be allowed.

Here I have found an answer for SQL Server, but I can't figure out how to do this in Google Sheets Query DISTINCT for only one Column

what I have:

A,             B,        C
[email protected], approved, 05/04/2019
[email protected], not set, 05/05/2019
[email protected], refunded, 05/06/2019
[email protected], approved, 05/06/2019
[email protected], approved, 05/07/2019
[email protected], approved, 05/07/2019

what I want:

A,             B,        C
[email protected], refunded, 05/06/2019
[email protected], approved, 05/07/2019
like image 739
Lucas Reis Avatar asked Jul 22 '19 13:07

Lucas Reis


1 Answers

you can use SORTN where the 3rd parameter is set to 2:

=SORTN(SORT(A1:C, 3, 1), ROWS(A:A), 2, 1, 0)

0

like image 76
player0 Avatar answered Nov 15 '22 07:11

player0