Wednesday, 1 October 2014

Delete records from table

By using DELETE query, you can delete records from a table.

Syntax
DELETE FROM table_name WHERE [condition];

mysql> select * from employee;
+----+-----------+-----------+--------+---------------------+
| id | firstName | lastName  | salary | mailId              |
+----+-----------+-----------+--------+---------------------+
|  1 | Madhav    | Ananda    | 100000 | krishna@krishna.com |
|  2 | Arjun     | Dhanunjay |  50000 | arjun@arjun.com     |
|  3 | jaideep   | Geera     |  25000 | ptr@ptr.com         |
+----+-----------+-----------+--------+---------------------+
3 rows in set (0.00 sec)


1. Delete record, where id is 2.
mysql> DELETE FROM employee where id=2;
Query OK, 1 row affected (0.07 sec)


mysql> select * from employee;
+----+-----------+----------+--------+---------------------+
| id | firstName | lastName | salary | mailId              |
+----+-----------+----------+--------+---------------------+
|  1 | Madhav    | Ananda   | 100000 | krishna@krishna.com |
|  3 | jaideep   | Geera    |  25000 | ptr@ptr.com         |
+----+-----------+----------+--------+---------------------+
2 rows in set (0.00 sec)


Prevoius                                                 Next                                                 Home

No comments:

Post a Comment