Jump to content

replace duplicates by chosing the newer timestamp


Recommended Posts

Im assuming a tmp table is needed so I made that... 

 

Ok so ( nfl as example again) ..

 

I made it possible to import csv file into NFL TABLE... then delete all rows with other players... except for brett farve and dan marino and say payton.

 

so now I have NFL TABLE with .. just three rows.. brett farve and dan marino and payton.

 

Let assume ... marino still plays .. but tomorrow he'll retire.. although we want his LAST csv data to stick..

 

 

tomorrow cron will run bring the new csv info  ... and dan marino isnt in the datafile anymore..

 

so todays info for marino will stay in the db.. but be his last...

 

so it runs it process... and the NEW payton and farve data came in..

 

Now... heres the part..  I have todays payton, farve and marino rows..

and also tommorrow in the db.. so now 5 rows..

 

those 5 rows have timestamps...

 

I want to delete duplicates by the player.. plus by the oldest times of the two...

 

so payton 10:00pm tomorrow

    payton  10:00pm  today

 

drops todays out of the db.. and keeps tomorrows.

 

all the while keeping marinos row cause it is not a duplicate.. and will remain in the db forever as his last..

 

get me?

 

****  basically how to delete duplicate rows by PLAYER_NAME  and the OLDEST of the two timestamps.

 

 

lol sorry for the long example..

 

 

this will select the data from the nfl rows that contain the newest date for each name

 

SELECT name, tstamp, othercols

FROM nfl n

JOIN (SELECT name, MAX(tstamp) as tstamp FROM nfl GROUP BY name) as x

USING (name,tstamp)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.