Deleting old MySQL Records

Discussion in 'PHP' started by CuBz, Oct 27, 2007.

  1. #1
    I want to delete old records from my forum so that when someone posts a topic it will delete the topic that is used the lessest

    The tablename is "topics" and i want to delete "lastreply"


    Thanks
     
    CuBz, Oct 27, 2007 IP
  2. theOtherOne

    theOtherOne Well-Known Member

    Messages:
    112
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    108
    #2
    DELETE FROM topics ORDER BY lastreply ASC LIMIT 0, 1
     
    theOtherOne, Oct 27, 2007 IP
  3. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #3
    ^^ Maybe I'd add something like WHERE topicid = X as well.
     
    nico_swd, Oct 27, 2007 IP
  4. theOtherOne

    theOtherOne Well-Known Member

    Messages:
    112
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    108
    #4
    But as I understood from the description, he just wants to delete the least used topic. I don't know whether he already knows the particular topic, but if he doesn't, he can only look for the lowest lastreply. And LIMIT 0, 1 ensures that he only deletes one topic, not all of them ;)
     
    theOtherOne, Oct 27, 2007 IP