to copy column from one table to another in psql I want to copy column User_id from public.&quot;firstapp_offer_Vendor&quot; to table firstapp_bid on the basis of oid, i.e. if oid in firstapp_offer_Vendor is equal to firstapp_bid.offer_id then user_id should be copied to vendor_id.
Here are my two tables:
Table firstapp_bid:
id   Bid  offer_id vendor_id        
1   &quot;123&quot;   1       null
2   &quot;123&quot;   6       null
3   &quot;123&quot;   13      null
4   &quot;120&quot;   13      null
5   &quot;140&quot;   14      null
6   &quot;130&quot;   14      null
7   &quot;140&quot;   14      null
8   &quot;150&quot;   14      null
9   &quot;123&quot;   15      null
10  &quot;123&quot;   16      null
11  &quot;120&quot;   16      null

Table first_app_offer_vendor:
id oid user_id
1   1   3
12  6   2
26  13  3
27  13  4
28  14  2
29  14  4
30  14  6
31  14  7
32  15  7
33  16  6
34  16  7

The output table should be:
id   Bid  offer_id vendor_id        
1   &quot;123&quot;   1       3
2   &quot;123&quot;   6       2
3   &quot;123&quot;   13      3
4   &quot;120&quot;   13      4
5   &quot;140&quot;   14      2
6   &quot;130&quot;   14      4
7   &quot;140&quot;   14      6
8   &quot;150&quot;   14      7
9   &quot;123&quot;   15      7
10  &quot;123&quot;   16      6
11  &quot;120&quot;   16      7

I tried implementing that using
INSERT INTO firstapp_bid 
(
   vendor_id
) 
SELECT 
   user_id 
FROM 
   public.&quot;firstapp_offer_Vendor&quot; 
WHERE
   public.&quot;firstapp_offer_Vendor&quot;.oid = public.&quot;firstapp_bid.offer_id

but it gives me the wrong output.
You don't need an insert here, as this is about adding new rows. You want rather to make an update. Something like
create table a(id int, v varchar(10));
create table b(id int, v varchar(10));

insert into a
select 1, 'a'
union all
select 2, 'b';

insert into b
select 1, null
union 
select 2, null;


update b set v = a.v
from a where a.id = b.id;