title: How to find consecutive values in column
body: <p>I have been given this task to try to detect some duplicate records in a table with a large volume of rows. The table comprises 2 joined tables. So to begin with I have:</p>
  
  <pre><code>select 
  b.event_number_id, b.tenure_number_id, a.work_start_date, a.work_stop_date, a.amount
  from
  MTA.mta_sow_event a, mta_tenure_event_xref b
  where
  a.event_number_id = b.event_number_id
  </code></pre>
  
  <p>Now we have a table to work from. The duplicate records have unique event_number_id, the reamining fields will contain identical data, so something like this:</p>
  
  <pre><code>| event_number_id |  tenure_number_id | work_start_date | work_stop_date |amount|
  |-----------------|-------------------|-----------------|----------------|------|
  |  5532733        | 688203            |     01-SEP-14   |  25-SEP-14     | 5000 |
  |  5532734        | 688203            |     01-SEP-14   |  25-SEP-14     | 5000 |
  </code></pre>
  
  <p>So, this is an example of a duplicate record. There are consecutive event_number_id's and all the remaining columns have identical information. We believe that our system has been creating duplicate events for some time now (this isn't supposed to happen), so I want to query the whole joined table and find anything that has rows that have exactly the same data, but different and consecutive event numbers.</p>
  
  <p>So far, I managed to make a simple query that shows me any rows that have identical information, excluding the event_number_id column:</p>
  
  <pre><code>select 
  b.tenure_number_id, a.work_start_date, a.work_stop_date, a.amount, count(*)
  from
  MTA.mta_sow_event a, mta_tenure_event_xref b
  where
  a.event_number_id = b.event_number_id
  group by
  b.tenure_number_id, a.work_start_date, a.work_stop_date, a.amount
  having
  count(*) &gt; 1
  </code></pre>
  
  <p>which returns:</p>
  
  <pre><code>|  tenure_number_id | work_start_date | work_stop_date |amount|Count(*)|
  |-------------------|-----------------|----------------|------|--------|
  | 688203            |     01-SEP-14   |  25-SEP-14     | 5000 |   2    |
  </code></pre>
  
  <p>The problem is, sometimes there are rows that have identical data, but could be valid, so the best we can do at this point is find any of these matching rows that have consecutive event_number_id's. This is where I am hung up. Is there a way to pull out only the rows that contain these consecutive numbers?</p>