Need help on update.

From: Nicholas I <nicholas(dot)domnic(dot)i(at)gmail(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Need help on update.
Date: 2010-10-21 07:43:42
Message-ID: AANLkTi=nyWz=SNYZ+uLNPeUKOTgSscVqZR6CRTUkL99z@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hi,

there are two tables, table1 and table2, each having same column name called
sn_no,name. i want to update table1 names with table2 where sn_no are same.

select * from table1;
sn_no | name
-------+-----------
1 | ramnad
2 | bangalore
3 | chennai

select * from table2;
sn_no | name
-------+-----------
1 | Hyderabad
2 | Delhi
3 | Bombay

Any help ?

I tried with , some of the queries like,

*UPDATE table1 SET name = (select name from table2) where table2.sn_no =
table1.sn_no;*
ERROR: missing FROM-clause entry for table "table2"
LINE 1: ...table1 SET name = (select name from table2) where table2.sn_.

*UPDATE table1 inner join table2 on table2.sn_no = table1.sn_no set
table2.name = table1.name;*
ERROR: syntax error at or near "inner"
LINE 1: UPDATE table1 inner join table2 on table2.sn_no = table1.sn_...

-Nicholas I

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Richard Huxton 2010-10-21 08:10:05 Re: Need help on update.
Previous Message Andreas 2010-10-18 23:05:02 Re: insert into table from list or array ?