Summary: The MySQL DELETE statement not only allows you to delete record from one table but also multiple tables. In this tutorial, you will learn how to use MySQL DELETE statement with examples.

To remove all rows or records from a database table you use MySQL DELETE statement. The following illustrates MySQL DELETE statement:

1 DELETE [LOW_PRIORITY] [QUICK]
2 FROM table_name
3 [WHERE conditions] [ORDER BY ...] [LIMIT rows]
1 DELETE [LOW_PRIORITY] [QUICK]
2 table_name[.*] [, table_name[.*] ...]
3 FROM table-references
4 [WHERE where_definition]
1 DELETE [LOW_PRIORITY] [QUICK]
2 FROM table_name[.*] [, table_name[.*] ...]
3 USING table-references
4 [WHERE where_definition]

Let’s examine the MySQL DELETE statements in details as below:

  • In the first form of MySQL DELETE statement, followed the DELETE FROM part is the table name where you want to delete records. The WHERE clause specifies condition to limit which rows you want to to remove. If a record meets WHERE condition, it will be removed from the database table permanently. If the WHERE clause is ignored in the MySQL DELETE statement, all rows of the table are deleted.
  • The second form of MySQL DELETE statement, It deletes records from multiple tables which reference to other table.
  • The third form of MySQL DELETE statement is quite similar to the second one except Using keyword is used instead of FROM keyword.

Let’s have a couple of examples of using MySQL DELETE statement in the sample database.

It is recommended that you make a copy of employee table before practicing with the MySQL DELETE statement.

Suppose you want to delete all employees in an office with officeNumber is 4, just execute the following query:

1 DELETE FROM employees
2 WHERE officeCode = 4

To delete all employees from all offices, just remove the WHERE condition as follows:

1 DELETE FROM employees

It will remove all rows from employees table.

If you want to delete all employee who work for office with officecode 1 and also that office. You can use the second form of MySQL DELETE statement to delete data from multiple tables as follows:

1 DELETE employees,offices
2 FROM employees,offices
3 WHERE employees.officeCode = offices.officeCode AND
4 offices.officeCode = 1

You can achieve the same above effect by using the third form of DELETE statement as below:

1 DELETE FROM employees,offices
2 USING employees,offices
3 WHERE employees.officeCode = offices.officeCode AND
4 offices.officeCode = 1

In this tutorial, you’ve learned various forms of MySQL DELETE statement to delete records from one or multiple database tables.

Related posts:

  1. How to Use MySQL Limit to Constrain Number of Returned Records
  2. Working with Tables – Part II
  3. Inserting Data into Database Tables
  4. Updating Data in Database Tables
  5. Managing Database Index in MySQL

Leave your comment

You must be logged in to post a comment.


Link Exchange Spritual Place for Bhakti | bhaktiguru.com Business Franchise in India | businessfranchiseindia.com Free Directory Submission & Link Submission | ab-directory.com Big Dwarka Business Listing | bigdwarka.com Kolkata Online Business Listing | onlinekolkata.com Patna Online Business Listing | onlinepatna.com Dwarka Online Business Listing | onlinedwarka.com Bihar Online | First Bihar's Portal | bihar-online.com Big Bihar Business Listing | bigbihar.com Dynamic Website Development | dynamicwebsitedeveloper.com Noida Online Business Listing | onlinenoida.com SEO Service Delhi & India | seoservicedelhi.com SEO Experts Delhi & India | seoexpertsdelhi.com Big Patna Business Listing | bigpatna.com Bihar schools Listing Free Schools Ad | biharschools.com Creative Websoft Solutions | Web Development India | creativewebsoft.us Bulk SMS Providers India | bulksmsproviders.net Online cbse Guides | onlinecbseguides.com Big Kolkata Business Listing | bigkolkata.com Handicap Shaadi.com | handicapshaadi.com Handicap Marriage.com | handicapmarriage.com India Home Tutors.com | indiahometutors.com Indian Property Guides.com | indianpropertyguides.com Online Stocks Community.com | onlinestockscommunity.com Free Article Submission | ab-articles.com Secret Dating Online.com | secretdatingonline.com Private DatingOnline.com | privatedatingonline.com Indian businessguides.com | indianbusinessguides.com Software Engineer Delhi | Meenu Khanna Bollywood & Hot Images | hibdy.com Free Computer & Online PHP Training | php2php.com Free Ignou Project & Assignment | ignouinfo.com PHP Programmer India | Web Developer India | bageshsingh.com Creative Websoft Solutions | Web Development IndiaBlog Link Exchange http://www.php2php.com/tutorial-blog/http://bageshsingh.com/bagesh-blog/http://www.bhaktiguru.com/bhaktigurublog/http://www.hibdy.com/desi-masala-blog/