Help: Deleting just one row in mysql...

Discussion in 'PHP' started by Skillman13, Nov 21, 2009.

  1. #1
    I have a cron job which I want to remove just one row from the database -the top row.

    How do I just remove/delete one row from a database?

    This is code for delete all I think, so how do I make it just delete one?
    -(Once that is sorted I can fix this rest -delete one ORDER BY Time DESC)

    DELETE FROM `Queue`

    So how do I?

    Thanks,

    James
     
    Skillman13, Nov 21, 2009 IP
  2. bizmagic

    bizmagic Well-Known Member

    Messages:
    145
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    103
    #2
    Use WHERE clause to uniquely specify the row you want to delete.
     
    bizmagic, Nov 21, 2009 IP
  3. Skillman13

    Skillman13 Peon

    Messages:
    229
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    DELETE * FROM `Queue` ORDER BY `Time` LIMIT 0 , 1

    That doesn't work, how can i make that work?
     
    Skillman13, Nov 21, 2009 IP
  4. Skillman13

    Skillman13 Peon

    Messages:
    229
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    bizmagic, it will just remove the top row -person at top of queue... I don't want to hassle the cron job with more code if there is a way to do this (delete row) without code, so is there?
     
    Skillman13, Nov 21, 2009 IP
  5. bizmagic

    bizmagic Well-Known Member

    Messages:
    145
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    103
    #5
    Try LIMIT 1 instead of LIMIT 0,1.
     
    bizmagic, Nov 21, 2009 IP
  6. Skillman13

    Skillman13 Peon

    Messages:
    229
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Fixed, thanks alot :) -Silly 0,1 :p
     
    Skillman13, Nov 21, 2009 IP
  7. bizmagic

    bizmagic Well-Known Member

    Messages:
    145
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    103
    #7
    Ha ha...no problem.
     
    bizmagic, Nov 21, 2009 IP
  8. getquicksolution

    getquicksolution Peon

    Messages:
    20
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    DELETE FROM `Queue` WHERE primid=somevalue

    note: primid should be primary key and somevalue should be the first id.
     
    getquicksolution, Nov 21, 2009 IP
  9. Freditpl

    Freditpl Peon

    Messages:
    28
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #9
    DELETE * FROM `Queue` ORDER BY `Time` ORDER BY `test2` LIMIT 1;
     
    Freditpl, Nov 22, 2009 IP