Delete a specific record on the basis of EmployeeId in MySQL

MySQLMySQLi Database

Let us first create a table −

mysql> create table DemoTable615 (EmployeeId varchar(100),EmployeeName varchar(100));
Query OK, 0 rows affected (0.62 sec)

Insert some records in the table using insert command −

mysql> insert into DemoTable615 values('EMP-101','Adam');
Query OK, 1 row affected (0.11 sec)
mysql> insert into DemoTable615 values('EMP-1001','David');
Query OK, 1 row affected (0.20 sec)
mysql> insert into DemoTable615 values('EMP-1002','Chris');
Query OK, 1 row affected (0.08 sec)
mysql> insert into DemoTable615 values('EMP-1003','Robert');
Query OK, 1 row affected (0.21 sec)

Display all records from the table using select statement −

mysql> select *from DemoTable615;

This will produce the following output −

+------------+--------------+
| EmployeeId | EmployeeName |
+------------+--------------+
| EMP-101    | Adam         |
| EMP-1001   | David        |
| EMP-1002   | Chris        |
| EMP-1003   | Robert       |
+------------+--------------+
4 rows in set (0.00 sec)

Following is the query to delete a specific record −

mysql> delete from DemoTable615 where EmployeeId='EMP-1002';
Query OK, 1 row affected (0.13 sec)

Let us check table records once again −

mysql> select *from DemoTable615;

This will produce the following output −

+------------+--------------+
| EmployeeId | EmployeeName |
+------------+--------------+
| EMP-101    | Adam         |
| EMP-1001   | David        |
| EMP-1003   | Robert       |
+------------+--------------+
3 rows in set (0.00 sec)
raja
Published on 22-Aug-2019 17:41:16
Advertisements