Postgres Join Delete Query

SQL-99 does not allow to delete data in a table when using JOINS. The reasons for this are quite obscure. Maybe it was considered too complicated to implement. Therefore for safety reasons it was not part of the standard.

As a result, MySQL implemented this feature and PostgreSQL rejected it.

The following query works under MySQL but fails under PostgreSQL:

 

DELETE h
FROM history AS h 
INNER JOIN term_node AS tn ON (h.nid = tn.nid) 
INNER JOIN term_data AS td ON (td.tid = tn.tid) 
WHERE h.uid = 2067 AND td.vid = 2

Sql Inner Join Update Query

create table 1 and table 2

 

CREATE TABLE Table1
(
Id INT,
FruitName Varchar( 100)
);

CREATE TABLE Table2
(
Id INT,
FruitName Varchar( 100)
);

Insert into Table1 Values ( 1,’Mango’ ), ( 2, ‘Graps’), (3, ‘Banana’);
Insert into Table2 Values ( 1,’Mango’ ), ( 2, ‘vitthal’), (4, ‘Orange’);
SELECT * FROM Table1 ;
SELECT * FROM Table2 ;
SELECT *
FROM Table1 T1 Inner Join Table2 T2
ON T1. Id = T2 .Id;

update table2 set FruitName=null where id>1

UPDATE Table2
SET FruitName = t1.FruitName
FROM Table1 as t1 INNER JOIN Table2 T2
ON T1. Id = t2.Id;