Copyright © 2005-2008 Andrea Tincani

AndreaPHP | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (Create HTML table from recordset)Next Topic (Simplified SQL command) New Topic New Poll Post Reply
AndreaPHP Forum : Database : Deleting only the old record
Poster Message
neutrall
Level: Scholar


Registered: 28-03-2004
Posts: 43

icon Deleting only the old record

Hi, I would like to find a magic query! I whish I could have a query in mySQL that will delete all record except the last 5 entered. All record entered are timestamp. The problem, I have no clue where to start for such a query.

DELETE FROM Previous_Login WHERE User_Id=1 ORDER BY LastConnect LIMIT 5,50;


The LIMIT clause work on the DELETE command, but with only one argument. EX :

DELETE FROM Previous_Login WHERE User_Id=1 ORDER BY LastConnect LIMIT 5;




____________________________
A Stick give a wise man something to think about... and a fool, something to put in is mouth.

22-06-2005 at 01:37 AM
View Profile Send Email to User Show All Posts Visit Homepage ICQ | Quote Reply
neutrall
Level: Scholar


Registered: 28-03-2004
Posts: 43

icon Re: Deleting only the old record

I did do a work arround :


<?php
$sql 
"SELECT Id FROM Previous_Login WHERE User_Id=$Id";
$result $this->db->query($sql);
If (
$result->size() > 5) {
    
$sql "DELETE FROM Previous_Login WHERE User_Id=$Id ORDER BY LastConnect LIMIT 1";
    
$result $this->db->query($sql);
}
?>



But I have to do 2 query insteed of one, which is not a efficient.

____________________________
A Stick give a wise man something to think about... and a fool, something to put in is mouth.

22-06-2005 at 01:44 AM
View Profile Send Email to User Show All Posts Visit Homepage ICQ | Quote Reply
AndreaPHP Forum : Database : Deleting only the old record
Previous Topic (Create HTML table from recordset)Next Topic (Simplified SQL command) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: AndreaVB

Copyright © 2005-2008 Andrea Tincani

Powered by: tForum tForum Edition b0.92p1
Originally created by Toan Huynh (Copyright © 2000)
Enhanced by the tForumHacks team.