Delete with join -- deleting related table entries?

From: Bryce Nesbitt <bryce1(at)obviously(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Delete with join -- deleting related table entries?
Date: 2006-02-08 17:14:11
Message-ID: 43EA26E3.9040903@obviously.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

When I delete a record from a certain table, I need to delete a
(possibly) attached note as well. How can I do this with postgres? The
tables are like this:

reservation
reservation_id
stuff...

isuse
issue_id
reservation_id
stuff..

note
issue_id
text comments...

A select that pulls out what I want to delete is:

SELECT reservation_id,issue_id,note_id,eg_note.comments FROM
eg_reservation
LEFT JOIN eg_issue USING (reservation_id)
LEFT JOIN eg_note USING (issue_id)
WHERE reservation_id > condition;

Can anyone help me turn this into a DELETE statement?

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message BigSmoke 2006-02-08 17:25:59 Re: Delete with join -- deleting related table entries?
Previous Message Tom Lane 2006-02-07 19:39:17 Re: trecherous subselect needs warning?