X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id A39269DC815 for ; Wed, 8 Feb 2006 13:14:23 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 91386-09 for ; Wed, 8 Feb 2006 13:14:22 -0400 (AST) Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id 3E75F9DC821 for ; Wed, 8 Feb 2006 13:14:21 -0400 (AST) Received: from outbound.internet-mail-service.net (outbound6.internet-mail-service.net [216.240.47.197]) by svr4.postgresql.org (Postfix) with ESMTP id 576B95AF055 for ; Wed, 8 Feb 2006 17:14:21 +0000 (GMT) Received: from idiom.com (idiom.com [216.240.32.1]) by outbound.internet-mail-service.net (Postfix) with ESMTP id 3874523FF74 for ; Wed, 8 Feb 2006 09:14:19 -0800 (PST) Received: from [192.168.1.109] (adsl-69-107-112-198.dsl.pltn13.pacbell.net [69.107.112.198]) by idiom.com (8.12.11/8.12.11) with ESMTP id k18HEIZa087761 for ; Wed, 8 Feb 2006 09:14:19 -0800 (PST) (envelope-from bryce1@obviously.com) Message-ID: <43EA26E3.9040903@obviously.com> Date: Wed, 08 Feb 2006 09:14:11 -0800 From: Bryce Nesbitt User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.12) Gecko/20050921 X-Accept-Language: en-us, en MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: Delete with join -- deleting related table entries? Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0 required=5 tests=[none] X-Spam-Score: 0 X-Spam-Level: X-Archive-Number: 200602/71 X-Sequence-Number: 24081 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?