How to update rows

The syntax of the UPDATE statement

      UPDATE table_name 
      SET column_name_1 = expression_1 [, column_name_2 = expression_2]... 
      [WHERE search_condition]
      

Update one column of one row

      UPDATE products 
      SET discountPercent = '10.00' 
      WHERE productName = 'Fender Telecaster';
      

Update multiple columns of one row

      UPDATE products 
      SET discountPercent = '25.00', 
          description = 'This guitar has great tone and smooth playability.' 
      WHERE productName = 'Fender Telecaster';
      

Update one column of multiple rows

      UPDATE products SET discountPercent = '15.00' 
      WHERE categoryID = 2;
      

Update one column of all rows in the table

      UPDATE products SET discountPercent = '15.00';
      

Use a subquery to update multiple rows

      UPDATE orders SET shipAmount = 0 
      WHERE customerID IN (
        SELECT customerID FROM customers WHERE lastName = 'Sherwood'
      );
      

Description

Warning

Back