Subject Find duplicate multi-row entries
Author Daniel Miller
I have a table like:

CREATE TABLE ROUTES
(
  NODE smallint NOT NULL,
  ROUTE_INDEX smallint NOT NULL,
  LINK_NODE smallint NOT NULL,
  QUALITY smallint,
  CONSTRAINT PK_ROUTES PRIMARY KEY (NODE,ROUTE_INDEX)
);

In use, this table can have from 0-8 rows per NODE. Similar to:
5557    1    1116    0
5557    2    1115    0
5557    3    5104    2
5557    4    5073    2
5557    5    5222    2
5557    6    5110    2

On a regular basis this table gets updated. In the process, I copy the current values to an archive table via a BEFORE UPDATE trigger:
CREATE TABLE ROUTE_HISTORY
(
  NODE smallint NOT NULL,
  ROUTE_INDEX smallint NOT NULL,
  LINK_NODE smallint NOT NULL,
  QUALITY smallint,
  ROUTE_UPDATED timestamp NOT NULL,
  CONSTRAINT PK_ROUTE_HISTORY PRIMARY KEY (NODE,ROUTE_INDEX,ROUTE_UPDATED)
);

I created these tables to monitor some conditions - and now I'm starting to try to use these for analysis.  One of the conditions I'm seeing is - often during the update there's actually no change.  As a result, my history table has an awful lot of duplicate records.  I don't think I need these.  So...I need a filter to find duplicate conditions - whereupon I'll decide either to not insert them to begin with, or prune them from the database, or maybe I'll keep them and just not display the duplicates for certain reports.

So the question is how to determine the duplicates.  My initial reaction is a stored procedure, which would perform the necessary processing - probably using some recursive loops.  But...is there a way to express this via a select statement?
--
Daniel