Re: From select to delete

From: "David Johnston" <polobo(at)yahoo(dot)com>
To: "'Alexander Farber'" <alexander(dot)farber(at)gmail(dot)com>, "'pgsql-general'" <pgsql-general(at)postgresql(dot)org>
Subject: Re: From select to delete
Date: 2011-10-28 17:00:51
Message-ID: 00e701cc9593$26847d90$738d78b0$@yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

-----Original Message-----
From: pgsql-general-owner(at)postgresql(dot)org
[mailto:pgsql-general-owner(at)postgresql(dot)org] On Behalf Of Alexander Farber
Sent: Friday, October 28, 2011 12:34 PM
To: pgsql-general
Subject: [GENERAL] From select to delete

Hello,

Is there maybe an easy way to delete that player (and all his games and
partners) or do I have to work with temp tables?

---/Original Message------

The easiest way is to create FOREIGN KEY relationships between the various
tables and allow "ON DELETE CASCADE" to do the work.

Otherwise you need to DELETE with an appropriate WHERE clause (and
sub-selects) or you can use the "USING" clause with the DELETE to add
additional condition tables.

DELETE FROM t1
USING (t2 JOIN t3 ON (...)) t_linked
WHERE t1.something = t_linked.something;

See the SQL Command (DELETE) section of the documentation for more details
and examples of DELETE
See the SQL Command (CREATE TABLE ) section of the documentation for
information on how to setup FOREIGN KEYS

David J.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Alexander Farber 2011-10-28 17:02:45 Re: From select to delete
Previous Message Merlin Moncure 2011-10-28 16:59:04 Re: nextval skips values between consecutive calls