Q:

How to delete a record if the next record in table as the same value in specific field

I have a table with repeated values in the cell_id (integer) field.
I want to delete records where the "n + 1" record has the same value as "n"
This way I will not have repeated values in records that are adjacent/contiguous.
Before
id | user_id | cell_id
25 | 5973    | 6051
26 | 5973    | 6051
27 | 5973    | 6051
28 | 5973    | 100
29 | 5973    | 256
30 | 5973    | 256
31 | 5973    | 6051
32 | 5973    | 6051

After
id | user_id | cell_id
25 | 5973    | 6051
28 | 5973    | 100
29 | 5973    | 256
31 | 5973    | 6051

A:

I would simply use a join, which is expressed in a delete via using:
delete from t
    using t t2
    where t2.cell_id = t.cell_id and t2.user_id = t.user_id and
          t2.id = t.id + 1;

