Tomás Morell
Tomás Morell

Reputation: 63

Removing exact duplicate rows from presto

With the following table (assuming it has many other rows and columns), how could I query it while removing duplicates?

order_id customer_name amount bill_type
1 Chris 10 sale
1 Chris 1 tip
1 Chris 10 sale

Note that while all 3 rows are about the same order, only row 3 is a duplicate -- since row 2 tells us about the tips of that order.

Using distinct order_id would remove rows 2 and 3, while I am looking to only remove row 3.

Appreciate any ideas

Upvotes: 6

Views: 3852

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269883

If you want a new result set, you can use:

select distinct t.*
from t;

I would suggest saving this into a new table, if you need to materialize the result.

Upvotes: 10

Related Questions