Let us first create a table −
mysql> create table DemoTable722 ( StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, StudentName varchar(100), StudentAge int ); Query OK, 0 rows affected (1.84 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable722(StudentName,StudentAge) values('Chris Brown',23) ; Query OK, 1 row affected (0.24 sec) mysql> insert into DemoTable722(StudentName,StudentAge) values('John Smith',21); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable722(StudentName,StudentAge) values('David Miller',22); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable722(StudentName,StudentAge) values('Adam Smith',20); Query OK, 1 row affected (0.24 sec) mysql> insert into DemoTable722(StudentName,StudentAge) values('Carol Taylor',24); Query OK, 1 row affected (0.39 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable722;
This will produce the following output -
+-----------+--------------+------------+ | StudentId | StudentName | StudentAge | +-----------+--------------+------------+ | 1 | Chris Brown | 23 | | 2 | John Smith | 21 | | 3 | David Miller | 22 | | 4 | Adam Smith | 20 | | 5 | Carol Taylor | 24 | +-----------+--------------+------------+ 5 rows in set (0.00 sec)
Following is the query to delete from MySQL table WHERE column equals value AND column2 equals value2 −
mysql> delete from DemoTable722 where StudentId=3 and StudentName='David Miller'; Query OK, 1 row affected (0.21 sec)
Let us check table records once again −
mysql> select *from DemoTable722;
This will produce the following output -
+-----------+--------------+------------+ | StudentId | StudentName | StudentAge | +-----------+--------------+------------+ | 1 | Chris Brown | 23 | | 2 | John Smith | 21 | | 4 | Adam Smith | 20 | | 5 | Carol Taylor | 24 | +-----------+--------------+------------+ 4 rows in set (0.00 sec)