Re: Delete from table conditionally

From: "Charles Clavadetscher" <clavadetscher(at)swisspug(dot)org>
To: "'Arup Rakshit'" <aruprakshit(at)rocketmail(dot)com>, "'Pgsql-general'" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Delete from table conditionally
Date: 2016-12-17 07:49:43
Message-ID: 034401d2583a$27865c30$76931490$@swisspug.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello

> -----Original Message-----
> From: pgsql-general-owner(at)postgresql(dot)org [mailto:pgsql-general-owner(at)postgresql(dot)org] On Behalf Of Arup Rakshit
> Sent: Samstag, 17. Dezember 2016 08:39
> To: Pgsql-general <pgsql-general(at)postgresql(dot)org>
> Subject: [GENERAL] Delete from table conditionally
>
> Hi,
>
> I am using Postgresql 9.5.
>
> Below is the sample data taken from the mail table with only required columns:
>
> id | question_id | answer_id | content
> ----+-------------+-----------+----------
> 2 | 25 | 270 | Arup
> 3 | 26 | 276 | Kajal
> 4 | 26 | 276 | Arup
> 5 | 27 | 280 | Kajal
> 6 | 25 | 270 | Arup
> 7 | 25 | 270 | Lalu
> 8 | 25 | 270 | Arup
> 9 | 26 | 274 | Dilip
> 10 | 25 | 270 | doli
> 11 | 25 | 270 | Arup
> (10 rows)
>
>
> Say, I know the id 6 where content is "Arup". Now from this row, I want to delete all next rows where the content is
> "Arup". How should I achieve this?

Assuming that "next" means id > 6:

DELETE FROM <tablename>
WHERE id > 6
AND content = 'Arup';

Regards
Charles

>
>
> Regards,
> Arup Rakshit
>
>
> --
> Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org) To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Kevin Grittner 2016-12-17 14:08:54 Re: [GENERAL] Love Your Database project — Thoughts on effectively handling constraints?
Previous Message Arup Rakshit 2016-12-17 07:39:28 Delete from table conditionally