The previous Lesson of MySql Lessons Series was about MySql Update Query and in this lesson will learn about the Delete Query in MySql.
Delete query in MySql is used to delete one or more records from a table. For the explanation of delete query consider the following test table:
The testtable shown in the above image has six records, we can use the delete query to delete all the six records from the table like this:
Another way of deleting all the records from the testtable would be this:
The delete queries above will delete all the records in the testtable as there is no use of the where clause in the query for deletion of a specific record or set of records. If we do not want to delete all the records in the table but only the records we choose to delete, then we can use where clause in our query to delete only selective records like this:
The above query will delete all the users from the testtable with names Albert. Similarly we can apply the where condition on the email column of the table, to delete all the users with email equal to a specific email we define i.e
Delete query in MySql is used to delete one or more records from a table. For the explanation of delete query consider the following test table:
The testtable shown in the above image has six records, we can use the delete query to delete all the six records from the table like this:
DELETE FROM `testtable`
Another way of deleting all the records from the testtable would be this:
DELETE * FROM `testtable`
The delete queries above will delete all the records in the testtable as there is no use of the where clause in the query for deletion of a specific record or set of records. If we do not want to delete all the records in the table but only the records we choose to delete, then we can use where clause in our query to delete only selective records like this:
DELETE FROM `testtable` WHERE `Name` = 'Albert'
The above query will delete all the users from the testtable with names Albert. Similarly we can apply the where condition on the email column of the table, to delete all the users with email equal to a specific email we define i.e
DELETE FROM `testtable` WHERE `Email` = 'john@gmail.com'
No comments:
Post a Comment