Search code examples
sqlprestotrino

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


Solution

  • 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.