Learn to Code SQL Example – SQL | DELETE Statement

(SQL Example for Citizen Data Scientist & Business Analyst)

 

SQL | DELETE Statement

The DELETE Statement in SQL is used to delete existing records from a table. We can delete a single record or multiple records depending on the condition we specify in the WHERE clause.

Basic Syntax:

DELETE FROM table_name WHERE some_condition;

table_name: name of the table
some_condition: condition to choose particular record.

Note: We can delete single as well as multiple records depending on the condition we provide in WHERE clause. If we omit the WHERE clause then all of the records will be deleted and the table will be empty.

Sample Table:
table1

Example Queries:

  • Deleting single record: Delete the rows where NAME = ‘Ram’. This will delete only the first row.
    DELETE FROM Student WHERE NAME = 'Ram';
    

    Output:
    The above query will delete only the first row and the table Student will now look like,

    ROLL_NO NAME ADDRESS PHONE Age
    2 RAMESH GURGAON XXXXXXXXXX 18
    3 SUJIT ROHTAK XXXXXXXXXX 20
    4 SURESH Delhi XXXXXXXXXX 18
    3 SUJIT ROHTAK XXXXXXXXXX 20
    2 RAMESH GURGAON XXXXXXXXXX 18
  • Deleting multiple records: Delete the rows from the table Student where Age is 20. This will delete 2 rows(third row and fifth row).
    DELETE FROM Student WHERE Age = 20;
    

    Output:
    The above query will delete two rows(third row and fifth row) and the table Student will now look like,

    ROLL_NO NAME ADDRESS PHONE Age
    1 Ram Delhi XXXXXXXXXX 18
    2 RAMESH GURGAON XXXXXXXXXX 18
    4 SURESH Delhi XXXXXXXXXX 18
    2 RAMESH GURGAON XXXXXXXXXX 18
  • Delete all of the records: There are two queries to do this as shown below,
    query1: "DELETE FROM Student";
    
    query2: "DELETE * FROM Student";
    

    Output:
    All of the records in the table will be deleted, there are no records left to display. The table Student will become empty!

 

MySQL Tutorials for Business Analyst: MySQL DELETE Query

 

Learn to Code SQL Example – SQL | DELETE Statement

Personal Career & Learning Guide for Data Analyst, Data Engineer and Data Scientist

Applied Machine Learning & Data Science Projects and Coding Recipes for Beginners

A list of FREE programming examples together with eTutorials & eBooks @ SETScholars

95% Discount on “Projects & Recipes, tutorials, ebooks”

Projects and Coding Recipes, eTutorials and eBooks: The best All-in-One resources for Data Analyst, Data Scientist, Machine Learning Engineer and Software Developer

Topics included: Classification, Clustering, Regression, Forecasting, Algorithms, Data Structures, Data Analytics & Data Science, Deep Learning, Machine Learning, Programming Languages and Software Tools & Packages.
(Discount is valid for limited time only)

Disclaimer: The information and code presented within this recipe/tutorial is only for educational and coaching purposes for beginners and developers. Anyone can practice and apply the recipe/tutorial presented here, but the reader is taking full responsibility for his/her actions. The author (content curator) of this recipe (code / program) has made every effort to ensure the accuracy of the information was correct at time of publication. The author (content curator) does not assume and hereby disclaims any liability to any party for any loss, damage, or disruption caused by errors or omissions, whether such errors or omissions result from accident, negligence, or any other cause. The information presented here could also be found in public knowledge domains.

Learn by Coding: v-Tutorials on Applied Machine Learning and Data Science for Beginners

Please do not waste your valuable time by watching videos, rather use end-to-end (Python and R) recipes from Professional Data Scientists to practice coding, and land the most demandable jobs in the fields of Predictive analytics & AI (Machine Learning and Data Science).

The objective is to guide the developers & analysts to “Learn how to Code” for Applied AI using end-to-end coding solutions, and unlock the world of opportunities!