SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Evangelist Scheisskopf's Avatar
    Join Date
    Nov 2004
    Location
    Southampton, UK
    Posts
    537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    updating field based on a value

    i need to update a float in a row in my table, based on whether the other two fields in the table, id, and name, are certain values. the thing is, the following won't work:

    Code:
    update yourtable
       set yourfloat = yourfloat + 1.5
     where id = 2
       and name = 'dave'
    because there may not exist a row where the id and name are both these values. so is there any way to test whether there is a row with these values, if so, do the code above, and if not, insert a new row with all this info.

    So i guess i am looking for some sort of mysql if statement.

    Thanks.

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,347
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    the IF statement in mysql applies to stored procedures which are supported only in version 5

    if you're on, let's say, 4.0.21, then you have a choice to make

    use application program scripting, e.g. php, or else if you really really want to use mysql's IF statement, upgrade to version 5

    which, by the way, is still in early beta status
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •