1

I was wondering if this is possible to update one column from values in different other columns... something like:

UPDATE table
    SET column1 = CASE column2,column3
        WHEN column2 == test AND column3 == 1 THEN 100
        WHEN (column2 LIKE %test1% OR column2 LIKE %test2%) AND column3 == 2 THEN 50
        ELSE 0
    END

Thanks for any answer!

EDIT : answer for others who might have the same problem:

UPDATE table
    SET column1 = CASE 
        WHEN column2 = test AND column3 = 1 THEN 100
        WHEN (column2 LIKE '%test1%' OR column2 LIKE '%test2%') AND column3 = 2 THEN 50
        ELSE 0
    END
Snipchain
  • 147
  • 2
  • 12

1 Answers1

1

Remove "column2, column3" after case and try following thing,

UPDATE table
    SET column1 = CASE WHEN column2 == test AND column3 == 1 THEN 100
        WHEN (column2 LIKE '%test1%' OR column2 LIKE '%test2%') AND column3 == 2 THEN 50
        ELSE 0
    END

following is the link to guide you more about CASE statement: http://dev.mysql.com/doc/refman/5.0/en/case.html

rene
  • 41,474
  • 78
  • 114
  • 152
Himanshu Sharma
  • 254
  • 1
  • 5