Basic Update query

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tony Wainwright

    #1

    Basic Update query

    Hi guys

    I'm pretty new to mysql and was just wondering if you can update multiple
    fields at the same time i.e:
    UPDATE tablename SET field1 = value1 AND field2 = value 2 etc... WHERE
    field0 = value;

    Cheers
    Tony


  • Jonathan

    #2
    Re: Basic Update query

    Tony Wainwright wrote:[color=blue]
    > Hi guys
    >
    > I'm pretty new to mysql and was just wondering if you can update multiple
    > fields at the same time i.e:
    > UPDATE tablename SET field1 = value1 AND field2 = value 2 etc... WHERE
    > field0 = value;
    >
    > Cheers
    > Tony
    >
    >[/color]

    Yes, you this is possible... but you can also use the following syntax:

    UPDATE tablename (field1, field2, ..., fieldn) SET VALUES (value1,
    value2, ..., valuen) WHERE field0 = value;

    Jonathan

    Comment

    • Gordon Burditt

      #3
      Re: Basic Update query

      >I'm pretty new to mysql and was just wondering if you can update multiple[color=blue]
      >fields at the same time i.e:
      >UPDATE tablename SET field1 = value1 AND field2 = value 2 etc... WHERE
      >field0 = value;[/color]

      Yes, but you don't use AND, you use a comma to separate different
      field assignments.

      I think the statement as you gave it would work, but it would only
      set field1, and it would do some funky boolean calculations for
      its value:

      UPDATE tablename SET field1 = ((value1) AND (field2 = value2)) WHERE
      ^ assignment ^comparison
      field0 = value;

      Instead use:

      UPDATE tablename SET field1 = value1, field2 = value2, ... WHERE
      field0 = value.

      Gordon L. Burditt


      Comment

      Working...