sql - how to find Duplicate records by comparing the previous records received in a table -


i have table

seq_num create_dt col1 col2 is_load 1 1/1/2014 b 2 2/1/2014 c d
3 3/1/2014 b

everyday data loaded table through loader. want write query should find duplicate data in current day record comparing previous days records , update column is_load = 'd'(as of duplicate) if duplicate record found.

so result should like

`seq_num  create_dt   col1  col2  is_load    1       1/1/2014         b                2       2/1/2014     c     d               3       3/1/2014         b              .          ....      .      .                .          ....      .      .    11      11/3/2014         b      d    ` 

thanks in advance !!!!!

try this:

update mytable m set is_load = 'd' exists (select null               mytable               m.col1 = col1                 , m.col2 = col2                 , m.seq_num > seq_num); 

this condition m.seq_num > seq_num helps avoid setting first entry 'd'.

if matters can change seq_num create_dt can leave entries loaded same day.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -