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: Regina Harter <rharter_at_emc-inc.com>
Date: Fri, 02 Nov 2001 10:34:57 -0800
Message-ID: <F001.003BB8D2.20011102103521@fatcity.com>

  t2.timestamp < t1.timestamp will delete the latest. It will actually delete anything greater than the earliest. You will notice I wrote
Delete where exists ...
which means delete anything where there was a match with an earlier timestamp.

At 06:10 PM 11/1/01 -0800, you wrote:
>t2.timestamp > t1.timestamp?
>
>he wants to delete the LATEST insert timestamp, right Paul?
>
>--- Regina Harter <rharter_at_emc-inc.com> wrote:
> > Try this:
> >
> > Delete from my_table t1
> > where a = 2 and exists
> > (select 'X' from my_table t2
> > where t2.a = t1.a
> > and t2.b = t1.b
> > and t2.c = t1.b
> > and t2.d = t1.d
> > and t2.timestamp < t1.timestamp)
> >
> > At 12:55 PM 11/1/01 -0800, you wrote:
> > >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: Regina Harter
> > INET: rharter_at_emc-inc.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).
>
>
>__________________________________________________
>Do You Yahoo!?
>Find a job, post your resume.
>http://careers.yahoo.com
>--
>Please see the official ORACLE-L FAQ: http://www.orafaq.com
>--
>Author: Rachel Carmichael
> INET: wisernet100_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: Regina Harter
  INET: rharter_at_emc-inc.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 Fri Nov 02 2001 - 12:34:57 CST

Original text of this message

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