Search Postgresql Archives

What is the best way to merge two disjoint tables?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Gurus,

I have two disjoint tables, for examples, of user lists.

Some users appear both tables. They may or may not have the same u_id.
Some users only appear one table.

I would like to merge tableB into tableA with the condition that each user has a unique id. Also I would like to keep u_id in the tableB. This requires to modify u_id of tableA if there are matching users but different u_id. Also those users only in tableA should change their u_id, if needed, to avoid any conflict with u_id from tableB.

Can someone show me an example SQL statement?

tableA:
 u_user  | u_id
----------+------
user1   |   46
user2   |   30
user4   |   22
user5   |   48
user7   |    6
user9    |    1
user11  |   45
user12  |   33

tableB:
 u_user  | u_id
----------+------
user1    |   46
user2    |   30
user3   |   22
user6   |   48
user8   |    6
user10  |    1

Thanks,

- Chansup


---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

              http://www.postgresql.org/docs/faq

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux