Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Mailing Lists -> Oracle-L -> RE: gnarly delete statement?

RE: gnarly delete statement?

From: DENNIS WILLIAMS <DWILLIAMS_at_LIFETOUCH.COM>
Date: Thu, 01 Nov 2001 13:01:40 -0800
Message-ID: <F001.003BACE0.20011101131518@fatcity.com>

Paul - Try this (may have a typo or two since I can't run it)

delete from mytable x

        where a.timestamp < (select max(timestamp)
                from mytable y
                where x.b = y.b
                and   x.c = y.c
                and   x.d = y.d
                and   x.a = 2)

This is a mod of the SQL statement in Corrigan and Gurry.

-----Original Message-----
Sent: Thursday, November 01, 2001 2:56 PM To: Multiple recipients of list ORACLE-L

Given a business rule that says a combination of three columns must be unique if and only if a fourth column equals a certain value, and if the table in question contains rows that violate this requirement, I'm trying to write a single SQL statement that will remove the duplicates.  Of each set of duplicate rows, I'll delete the one with the latest insert timestamp.

Let's call the columns

a b c d timestamp

The combination of b, c, and d must be unique if a = 2.

I can get the duplicate row values along with the latest timestamp via

select max(tstamp), a, b, c from
my_table group by a, b, c having count(*) > 1

But I can't figure out how to use that in a delete statement.

Suggestions greatly appreciated!

Paul Baumgartel



Do You Yahoo!?
Make a great connection at Yahoo! Personals. http://personals.yahoo.com
--

Please see the official ORACLE-L FAQ: http://www.orafaq.com
--

Author: Paul Baumgartel
  INET: treegarden_at_yahoo.com
Fat City Network Services    -- (858) 538-5051  FAX: (858) 538-5051
San Diego, California        -- Public Internet access / Mailing Lists
--------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail message to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in the message BODY, include a line containing: UNSUB ORACLE-L (or the name of mailing list you want to be removed from). You may also send the HELP command for other information (like subscribing).
--

Please see the official ORACLE-L FAQ: http://www.orafaq.com
--

Author: DENNIS WILLIAMS
  INET: DWILLIAMS_at_LIFETOUCH.COM
Fat City Network Services    -- (858) 538-5051  FAX: (858) 538-5051
San Diego, California        -- Public Internet access / Mailing Lists
--------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail message to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in the message BODY, include a line containing: UNSUB ORACLE-L (or the name of mailing list you want to be removed from). You may also send the HELP command for other information (like subscribing). Received on Thu Nov 01 2001 - 15:01:40 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US