pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michael Mattox <michael.mattox@verideon.com>
To: pgsql-sql@postgresql.org
Subject: How to delete multiple rows from multiple joined tables
Date: Mon, 26 May 2003 15:48:16 +0200
Message-ID: <CJEBLDCHAADCLAGIGCOOAEMHCHAA.michael.mattox@verideon.com> (raw)

I'm trying to use SQL to delete multiple rows from multiple tables that are
joined together.  From what I've seen delete can only delete from a single
table, which is OK because I can just do separate deletes for each table.
But the problem is how do I specify which rows to delete?  For example:

Table A is joined to Table B
Table B is joined to Table C

I want to delete all rows in table C & B that correspond to a row in Table
A.  Here's my exact SQL which actually deletes all the rows:

delete from monitorstatusitemx where monitorx.namex='STRESS_TEST' and
monitorstatusx.jdoidx = monitorstatus_statusitemsx.jdoidx and
monitorstatus_statusitemsx.statusitemsx =
monitorstatusitemlistd8ea58a5x.jdoidx and
monitorstatusitemlistd8ea58a5x.statusitemlistx = monitorstatusitemx.jdoidx

(It's a little ugly because I'm using JDO which generates the schema.
Unfortunately deletes with JDO are very slow so I need to use SQL for this.)

Michael





view thread (2+ messages)  latest in thread

Message-ID: <CJEBLDCHAADCLAGIGCOOAEMHCHAA.michael.mattox@verideon.com>
Permalink:  ../CJEBLDCHAADCLAGIGCOOAEMHCHAA.michael.mattox@verideon.com/
Also on:    postgresql.org/message-id/CJEBLDCHAADCLAGIGCOOAEMHCHAA.michael.mattox@verideon.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: michael.mattox@verideon.com
  Subject: Re: How to delete multiple rows from multiple joined tables
  In-Reply-To: <CJEBLDCHAADCLAGIGCOOAEMHCHAA.michael.mattox@verideon.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox