
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
MySQL edit and update records including employee salary
The UPDATE command is used in MySQL to update records. With it, the SET command is used to set new values. Let us first create a table −
mysql> create table DemoTable ( EmployeeId int NOT NULL AUTO_INCREMENT PRIMARY KEY, EmployeeName varchar(50), EmployeeSalary int ); Query OK, 0 rows affected (0.57 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable(EmployeeName,EmployeeSalary) values('Chris',56780); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable(EmployeeName,EmployeeSalary) values('Robert',45670); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable(EmployeeName,EmployeeSalary) values('Mike',87654); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable(EmployeeName,EmployeeSalary) values('David',34569); Query OK, 1 row affected (0.11 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+------------+--------------+----------------+ | EmployeeId | EmployeeName | EmployeeSalary | +------------+--------------+----------------+ | 1 | Chris | 56780 | | 2 | Robert | 45670 | | 3 | Mike | 87654 | | 4 | David | 34569 | +------------+--------------+----------------+ 4 rows in set (0.00 sec)
Following is the query to update records and set new values −
mysql> update DemoTable set EmployeeSalary=EmployeeSalary+12346; Query OK, 4 rows affected (0.14 sec) Rows matched: 4 Changed: 4 Warnings: 0
Let us check the table records −
mysql> select *from DemoTable;
This will produce the following output −
+------------+--------------+----------------+ | EmployeeId | EmployeeName | EmployeeSalary | +------------+--------------+----------------+ | 1 | Chris | 69126 | | 2 | Robert | 58016 | | 3 | Mike | 100000 | | 4 | David | 46915 | +------------+--------------+----------------+ 4 rows in set (0.00 sec)
- Related Articles
- Update salary field value with 10 percent of each employee in MongoDB
- Find max and second max salary for a MySQL Employee table?
- Find max and second max salary for a MySQL Employee table using subquery?
- How can we fetch a second highest salary of an employee from a MySQL table?
- MySQL update multiple records in a single query?
- The salary for a month of an employee is Rs. 4000. The annual salary of the employee is1) RS 480002) RS 240003) RS 120004) RS 8000
- MySQL regular expression to update a table with column values including string, numbers and special characters
- Display only the employee names with specific salaries in MongoDB documents with employee records?
- How to update a range of records in MySQL?
- MySQL queries to update date records with NULL values
- MySQL Stored Procedure to update records with certain condition?
- What are employee retention and employee attrition?
- How to update records in a column with random numbers in MySQL?
- Select highest salary in MySQL?
- MongoDB query to get minimum and maximum value from documents including some duplicate records

Advertisements