Delete a specific record from a MySQL table by using AND in WHERE clause


MySQL AND is used in WHERE to fetch a record by filtering using multiple conditions. Let us first create a table−

mysql> create table DemoTable
   -> (
   -> Id int,
   -> Name varchar(20)
   -> );
Query OK, 0 rows affected (0.70 sec)

Insert some records in the table using insert command −

mysql> insert into DemoTable values(101,'Chris');
Query OK, 1 row affected (0.13 sec)
mysql> insert into DemoTable values(102,'David');
Query OK, 1 row affected (0.51 sec)
mysql> insert into DemoTable values(103,'Bob');
Query OK, 1 row affected (0.14 sec)

Display all records from the table using select statement −

mysql> select * from DemoTable;

This will produce the following output −

+------+-------+
| Id   | Name  |
+------+-------+
| 101  | Chris |
| 102  | David |
| 103  | Bob   |
+------+-------+
3 rows in set (0.00 sec)

Here is the query to delete a record −

mysql> delete from DemoTable where Id=102 and Name='David';
Query OK, 1 row affected (0.20 sec)

Let us check the table records once again −

mysql> select * from DemoTable;

This will produce the following output −

+------+-------+
| Id   | Name  |
+------+-------+
| 101  | Chris |
| 103  | Bob   |
+------+-------+
2 rows in set (0.00 sec)

Updated on: 26-Feb-2020

102 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements