Update Query (with calculation & condition) - Please Help

Discussion in 'PHP' started by KingCobra, Sep 27, 2011.

  1. #1
    My mysql table name is: mytable

    Here is the table structure (one column and values)

    myid
    -----
    X1
    X3
    X2
    X6
    X6
    X9
    X1
    X7
    X5
    X4
    X8

    How can I write one line query to update (decrease 1) all myid values where myid >= X5
    So the result will look loke the following:

    myid
    -----
    X1
    X3
    X2
    X5
    X5
    X8
    X1
    X6
    X4
    X4
    X7

    I want to use it with php.

    Thanks in advance.
     
    KingCobra, Sep 27, 2011 IP
  2. sarahk

    sarahk iTamer Staff

    Messages:
    28,899
    Likes Received:
    4,555
    Best Answers:
    123
    Trophy Points:
    665
    #2
    Surely you've just discovered why its better to have a normalised table? This is just a sophisticated text file IMO.

    Put the values in two columns, add an id column (just because). You will find it easier to concatenate then to split and add/subtract.
     
    sarahk, Sep 28, 2011 IP