REPLACE INTO need to have a added field

Discussion in 'MySQL' started by ched, Jun 18, 2010.

  1. #1
    I am trying to use REPLACE INTO to update a table. It is working fine but I would like to have 2 fields:
    datetime - Added to table
    datetime - Updated

    The Updated datetime is fine but I cant work out how to not 'update' the Added to Table field. I just want a field that records the datetime that the record was first added to my table.

    Any ideas?

    Thanks
     
    ched, Jun 18, 2010 IP
  2. tycoon.vg

    tycoon.vg Peon

    Messages:
    25
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    update tblName set Updated = nnn where ...
    Added to Table field will be the same
     
    tycoon.vg, Jun 19, 2010 IP
  3. ched

    ched Active Member

    Messages:
    185
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    90
    #3
    Cheers for the reply. I eventually came up with the following solution:

    INSERT INTO myTable ( data.......... CreateTime Now())ON DUPLICATE KEY UPDATE (data............UpdateTime Now())

    So INSERT into myTable if the Primary Key Duplicate error UPDATE the myTable.
    So I dont need to see if a record exists before choosing to INSERT or UPDATE.
     
    ched, Jun 19, 2010 IP