sql delete more than 1 record

Discussion in 'PHP' started by exoskeleton, Jun 29, 2012.

  1. #1
    dear masters... could you please help me how to delete more than 1 record in the same field example

    DELETE FROM `employee` WHERE emp_id = 6 and emp_id = 15

    it doesnt work... whew... can you modify this sql delete statement of mine in order to work...

    thanks in advance...
     
    exoskeleton, Jun 29, 2012 IP
  2. Magina™

    Magina™ Active Member

    Messages:
    258
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #2
    DELETE FROM tbl_name WHERE col_id = 6 AND col_id = 15
     
    Magina™, Jun 29, 2012 IP
  3. afstanislav

    afstanislav Greenhorn

    Messages:
    31
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    16
    #3
    DELETE FROM employee WHERE emp_id IN ('1','2') or IN(1,2)

    I don't remember exactly :)
     
    afstanislav, Jun 29, 2012 IP
  4. ssmm987

    ssmm987 Member

    Messages:
    180
    Likes Received:
    4
    Best Answers:
    3
    Trophy Points:
    43
    #4
    If it needs to be either 12 or 15, use the or statement:

    DELETE FROM `employee` WHERE emp_id = 6 or emp_id = 15
     
    ssmm987, Jun 29, 2012 IP
  5. 137th Gebirg

    137th Gebirg Active Member

    Messages:
    70
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    91
    #5
    Yep, the "AND" in your query is what killed you, exoskeleton. A unique identifying primary key cannot be one number AND another simultaneously. That's why it needed to be changed to "OR" as ssmm987 mentioned. I do prefer the "IN" operator for stuff like this, though.
     
    137th Gebirg, Jun 29, 2012 IP
  6. exoskeleton

    exoskeleton Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    thank you very much sir... this really works for me...

    to all who replied.. thank you very much masters...
     
    exoskeleton, Jun 29, 2012 IP