| From: | Chansup Byun <Chansup(dot)Byun(at)sun(dot)com> |
|---|---|
| To: | pgsql-general(at)postgresql(dot)org |
| Subject: | What is the best way to merge two disjoint tables? |
| Date: | 2007-09-07 16:05:07 |
| Message-ID: | 46E176B3.7040802@sun.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-general |
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
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Gavin M. Roy | 2007-09-07 16:08:04 | Re: Connection Pooling directly on Postgres Server |
| Previous Message | Rodrigo De León | 2007-09-07 15:59:41 | Re: stored procedure |