Re: delete with self join

From: Thomas Burdairon <tburdairon(at)entelience(dot)com>
To: garry saddington <garry(at)schoolteachers(dot)co(dot)uk>
Cc: pgsql-general(at)postgresql(dot)org, Richard Huxton <dev(at)archonet(dot)com>
Subject: Re: delete with self join
Date: 2007-04-17 09:12:48
Message-ID: D02A5D1D-A9B6-49B0-AEEA-2FF21D9842BD@entelience.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Apr 17, 2007, at 11:07, garry saddington wrote:
>>
>
> I am keeping a record of siblings in a school. The user chooses one
> student and there siblings such that id's are entered into a table as
> such:
> TABLE SIBLINGS:
>
> principal sibling
> 809 234
> 809 785
> 809 345
> 809 809
>
> 809 is a sibling of all of them, but of course 234 is a sibling of
> 785.
> To retrieve siblings I use this query:
>
> SELECT
> students.studentid,students.firstname,students.surname,students.year,s
> tudents.pastoralgroup,students.dob
> FROM siblings c, siblings c2,students
> WHERE c.principal = c2.principal
> and c.sibling=234 (this value is supplied in a variable)
> and c2.sibling=students.studentid
>
> What I am trying to do is to allow the user to correct input
> mistakes by
> deleting all the siblings of one family at the same time by choosing
> just one of the siblings. I hope this clears things up.
> Regards
> Garry
>
What about a
DELETE FROM siblings WHERE principal IN (SELECT principal FROM
siblings WHERE sibling = 42)
?

Thomas

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Richard Huxton 2007-04-17 09:15:30 Re: delete with self join
Previous Message garry saddington 2007-04-17 09:07:14 Re: delete with self join