How to add 5 columns in MySQL to a total

Discussion in 'MySQL' started by traian1, Jul 17, 2009.

  1. #1
    Hi,
    I'm in a bit of a mess. I just can't get this command to work.

    UPDATE `table` SET votestotal = SUM(vote1, vote2, vote3, vote4, vote5);

    I just want to update all my votestotal with the values from vote1, vote2..., vote5.

    table
    id votestotal vote1 vote2 vote3 vote4 vote5
    1 null 4 5 3 3 1
    2 null 5 23 12 3 5
    3 null 32 3 12 1 0

    Just want to update the null values with the corresponding votes... i changed the programing now and it will do it, but i still need the previous votes totaled.

    I have about 5,000 users that I need this updated [if it matters]

    Any ideas?

    Just figured it out:
    UPDATE `table` SET votestotal = (SELECT (vote1 + vote2 + vote3 + vote4 + vote5));
     
    traian1, Jul 17, 2009 IP
  2. ajaXpert

    ajaXpert Member

    Messages:
    41
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #2
    you don't need to use select again
     
    ajaXpert, Aug 20, 2009 IP