In this article, we will discuss how we can use a SQL join with a delete statement.
The syntax for using a delete statement with a SQL join can be expressed as shown:
FROM table1 JOIN table2 ON
table1.attribute_name = table2.attribute_name
Let us start by creating sample tables and data as shown in the provided queries.
CREATE TABLE code_base(
INSERT INTO developers(name, department)
('Taylor Williams', 'Game developer'),
('Linda Moore', 'Full-Stack Developer'),
('Mary Smith', 'Database Developer');
INSERT INTO code_base(repo_id, commit)
The above queries create two tables and add sample data.
To delete a row in the code_base table with the commit value of 1 using a join, we can run a query as shown:
FROM code_base, JOIN developers ON
developes.id = code_base.commit
WHERE commit = 1;
The query above should remove the row where the commit value is 1.
This short article illustrates how to use a delete statement within a join query.