skip to Main Content

Postgresql – Update records by matching with each other within one table

I have the following table: create table sales (id,transaction_ref,type,amount,je_id) as values (1,'a','invoice',100,null) ,(2,'b','invoice',200,null) ,(3,'c','invoice',300,null) ,(4,'d','invoice',400,null) ,(5,'a','entry',10,null) ,(6,'b','entry',20,null) ,(7,'c','entry',30,null) ,(8,'d','entry',40,null); I want to match the records on the basis of transaction_ref and then update the ids of entry type records in…

VIEW QUESTION

Joining two tables with a joint result in Postgresql

There are two tables. table1 select tt1.* from (values(1,'key1',5),(2,'key1',6),(3,'key1',7) ) as tt1(id, field2,field3) table2 select tt2.* from (values(4,'key1',null),(2,'key1',null),(3,'key1',null)) as tt2(id, field2,field3) How can I combine these two tables in a query to get the result like this? select tt2.* from…

VIEW QUESTION
Back To Top
Search