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 |
No comments:
Post a Comment
It’s all about friendly conversation here at small review :) I’d love to be hear your thoughts!
Be sure to check back again because I do make every effort to reply to your comments here.