Re: delete with self join

Поиск
Список
Период
Сортировка
От Thomas Burdairon
Тема Re: delete with self join
Дата
Msg-id D02A5D1D-A9B6-49B0-AEEA-2FF21D9842BD@entelience.com
обсуждение исходный текст
Ответ на Re: delete with self join  (garry saddington <garry@schoolteachers.co.uk>)
Список 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




В списке pgsql-general по дате отправления:

Предыдущее
От: garry saddington
Дата:
Сообщение: Re: delete with self join
Следующее
От: Richard Huxton
Дата:
Сообщение: Re: delete with self join