This article is half-done without your Comment! *** Please share your thoughts via Comment ***
In this post, I am sharing a simple example of DELETE INNER JOIN statement in PostgreSQL.
Many of the database developers are exploring the PostgreSQL so DELETE a table from another table which is a very common requirement so I am sharing a simple example.
Create two sample tables with data:
1 2 3 4 5 |
CREATE TABLE ABC (ID INT, Name CHARACTER VARYING); CREATE TABLE XYZ (ID INT, Name CHARACTER VARYING); INSERT INTO ABC VALUES (1,'aaa'),(2,'bbb'),(3,'ccc'); INSERT INTO XYZ VALUES (1,'zzz'),(2,'yyy'),(3,'xxx'),(4,'www'); |
DELETE INNER JOIN:
1 2 3 |
DELETE FROM XYZ X USING ABC AS A WHERE A.ID = X.ID |
Check the result:
1 2 3 4 5 |
SELECT *FROM XYZ; id | name ---------------------- 4 | www |