I have duplicate data in a table called bank_currency that looks like this:
currencyid | bankid
--------------------
8 1
8 1
8 1
16 2
16 2
16 2
14 3
14 3
14 3
I have no idea why the data has been duplicated in triplicate, but I need to get rid of all the duplicates and keep only one of each row. So I end up like this:
currencyid | bankid
--------------------
8 1
16 2
14 3
I cannot ORDER BY the bankid or currencyid to tell postgresql which row to keep, because they are duplicate. Perhaps an order by ROW_NUMBER (if thats possible) and just keep the lowest ROW_NUMBER? Any suggestions greatly appreciated.
SELECT DISTINCT currencyid, bankid FROM yourtable;?DELETEstatementDISTINCTwrite it into a temp table or what-have-you, delete all records from your existing table and then blow the records from your temp table into your original table. I think handling this with a single DELETE statement is going to introduce a level of complexity and risk that I, personally, wouldn't be comfortable with in my database.