Mysql UPDATE various ways

MySQL UPDATE various ways will teach you to use update statement with respect to various problem statement. Some of the problem statement are as follow.

Mysql UPDATE various ways

MySQL UPDATE various ways


1.Basic Update

  • Below query will update the first_name to ‘Max’


  • Instead of updating single record at a time it is good practice to update records in bulk
  • For bulk update here we are assigning the policyId to each employee based on their OrgId if OrgId=’1′ then it will assign ‘4’ as policyId.


  • If ORDER BY clause is there in UPDATE query in this case rows are updated in the specified ORDER
  • LIMIT clause specifies limit on the number of rows that can be updated
  • ORDER BY and LIMIT cannot be used for multi table update.

4.Multiple Table UPDATE

  • It updates rows in each specified tables that satisfy the conditions
  • Each matching row is updated once, even if it matches the conditions multiple times
  • The below query will update employee_transaction and attendance_transaction tables respectively with values by setting employee_transaction.status=1 from employee_transaction table and attendance_transaction.process_status from attendance_transaction table.



Leave a Reply

Your email address will not be published. Required fields are marked *