DELETE STATEMENT

The DELETE statement allows to delete one row, multiple rows and all rows in a table. It supports subquery based deletes, to limit the number of rows. You can use join or subquery to get to exact rows which needs to be deleted. Delete query without WHERE or clause will delete all rows.

Syntax : DELETE FROM TABLE_NAME [WHERE Condition];

Delete Example

DROP TABLE IF EXISTS Users;
CREATE TABLE IF NOT EXISTS Users (
Username Text Primary Key
, FirstName Text
, LastName Text
);
 

INSERT INTO Users(Username, FirstName, LastName) values ('johnd','John','Dekota');
INSERT INTO Users(Username, FirstName, LastName) values ('maryd','Mary','Denware');
INSERT INTO Users(Username, FirstName, LastName) values ('scotth','Scott','Hamilton');

SELECT * FROM Users;

Delete Query

Following query will delete one row from users table.

DELETE FROM Users
WHERE Username = 'johnd' ;

SELECT * FROM Users;

Delete with where clause

Delete Subquery with Limit

DELETE FROM Users
WHERE Username = ( SELECT Username FROM Users WHERE Username = 'scotth');

SELECT * FROM Users;

Delete subquery