Delete query in sql

Delete query in sql

Blog Bustle 08/02/2020

What is delete query in sql?

Delete query is used to delete records in table. Many records can be deleted at a time. It depends on where condition.

Delete query syntax

delete from table_name where condition;

You can specify one or more condition by using where clause and combine more conditions by using 'and/or' operator.

delete from student where name='mihir'

delete from student where name='mihir' and email ='mihir@gmail.com'

both condition should be true in this delete query in sql otherwise table will remain same as before.

delete from student where name='mihir' or name ='harshit'

atleast one condition should be true in this delete query in sql otherwise table will remain same as before.

There are two methods to write delete query in mysql:

Method 1: When where condition is given

We have student table.

delete query in sql

We want to delete all rows in table where email is 'mihir@gmail.com' and name is 'mihir' then query will be

delete from student where email='mihir@gmail.com' and name='mihir'

delete query in sql

Method 2: When where condition is not given

If we do not write where condition in delete query in sql, all rows from student table will get deleted. We are going to delete all rows in student table and query will be

delete from student

delete query in sql

Other important links

Insert query in mysql

Update query in mysql

Select query in mysql

Difference between sql and mysql

Create Database in mysql

Delete query in sql searches:

Tags: #mysql