From: | "Igal (at) Lucee(dot)org" <igal(at)lucee(dot)org> |
---|---|
To: | pgsql-general <pgsql-general(at)postgresql(dot)org> |
Subject: | Delete Duplicates with Using |
Date: | 2017-10-14 06:20:15 |
Message-ID: | d2205343-8d46-c6be-05e4-72f0fffba644@lucee.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Hello,
I run the SQL query below to delete duplicates from a table. The
subquery is used to identify the duplicated rows (row_num is a BIGSERIAL
column).
/** delete older copies of duplicates */
DELETE FROM table_with_duplicatesAS T
WHERE row_num IN (
SELECT T1.row_num
FROM table_with_duplicates AS T1
JOIN table_with_duplicates AS T2
ON T1.column_1 = T2.column_1
AND T1.column_2 = T2.column_2
AND T1.column_3 = T2.column_3
AND T1.row_num < T2.row_num
);
Can anyone tell me how to rewrite that query to use the USING clause and
hopefully remove the subquery?
The documentation mentions USING but there is no example and the only
examples I found online are very trivial.
Thanks,
Igal Sapir
Lucee Core Developer
Lucee.org <http://lucee.org/>
From | Date | Subject | |
---|---|---|---|
Next Message | legrand legrand | 2017-10-14 07:18:13 | Where to find development builds of pg for windows |
Previous Message | Thomas Kellerer | 2017-10-13 21:36:51 | Re: Multiple Schemas vs. Multiple Databases |