If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > select double entrys sorted by unixtime

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-09-06, 21:12
DkR3 DkR3 is offline
Registered User
 
Join Date: Oct 2005
Posts: 2
select double entrys sorted by unixtime

hi @all i have a big problem whit my db than i have double entrys on it.

so i select all double entrys whit:

SELECT DISTINCT id, unixtime, ab, cd, de
FROM db
GROUP BY ab
HAVING count( ab ) >1

now i have all dubbel entry
ok thats works but the fault is i have select the oldes entry to delete but i want to delete not the oldest double entrys i wll delete the newest and the oldest let stay.

now my question give it a way to sort on the select the newst entry and not the oldest

i hoppe any1 understand what i mean and can help me


thx
and sorry for my bad englisch
Reply With Quote
  #2 (permalink)  
Old 02-11-06, 08:11
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
your english is pretty good

here is one method (there are others) --

step 1 -- BACK UP YOUR DATA FIRST

step 2 -- create a table of the rows to keep

Code:
create table keepers
select one.id
     , one.unixtime
     , one.ab
     , one.cd
     , one.de
  from db as one
inner
  join db as two
    on one.ab = two.ab
group
    by one.id
     , one.unixtime
     , one.ab
     , one.cd
     , one.de
having one.unixtime = max(two.unixtime)
step 3 -- drop table db

step 4 -- rename table keepers to db
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 02-11-06, 16:25
DkR3 DkR3 is offline
Registered User
 
Join Date: Oct 2005
Posts: 2
hi man big big thx this works perfect.

thx
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On