MySQL Forums
Forum List  »  Newbie

Re: How do I delete all but most recent record?
Posted by: Roland Bouman
Date: July 26, 2005 06:05PM

Well, you could use a modified version of the select I posted earlier, so:

insert
into log_table_hold (
member_name
, member_id
, ip_address
, running_time
, session_id
, member_group
)
select member_name
, member_id
, ip_address
, running_time
, session_id
, member_group
from log_table all_entries
where running_time = (
select max(running_time)
from log_table last_entry
where all_entries.member_name = last_entry.member_name
and all_entries.ip_address = last_entry.ip_address
)

would insert only the latest entries into the temptable.

Note that you cannot rely to yield this but one record per member name/ip address, as two records could exist within one second.

Options: ReplyQuote


Subject
Written By
Posted
Re: How do I delete all but most recent record?
July 26, 2005 06:05PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.