SQL
9. Delete Query

Delete Query

Delete query is used to delete rows from a table based on a condition.

Let's create a table named info with columns name and rollnumber.

delete_query.sql
CREATE TABLE info (
name VARCHAR(50),
rollnumber INT PRIMARY KEY
);
 
-- INSERT values into the table
INSERT INTO info (name, rollnumber)
VALUES
("Swayam", 1), ("Raj",2), ("Raj", 3);

Now let's see all the rows in the table.

select_query.sql
SELECT * FROM info;

Output:

namerollnumber
Swayam1
Raj2
Raj3

Now let's delete the row where name is Raj.

delete_query.sql
DELETE FROM info WHERE name = "Raj";

Now let's see all the rows in the table.

select_query.sql
SELECT * FROM info;

Output:

namerollnumber
Swayam1