pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedRe: DB question - Merging data from one table to another.
2+ messages / 2 participants
[nested] [flat]
* Re: DB question - Merging data from one table to another.
@ 2004-04-01 15:27 malia, sean <malia_sean@emc.com>
0 siblings, 1 reply; 2+ messages in thread
From: malia, sean @ 2004-04-01 15:27 UTC (permalink / raw)
To: pgsql-sql
Hello,
I'm not sure if this is even possible, but I'll throw it by you anyway.
Say I have 2 tables:
Table1: With columns number and name
1.1 test1
1.2 test2
1.3 test3
1.4 test4
Table2: With column number and results
1.1 pass
1.2 fail
1.3 pass
1.4 fail
What I would like to do is add a new column to Table2 called name and
populate the name from table 1 and add it to table 2. So, table 2 will look
like:
1.1 pass test1
1.2 fail test2
1.3 pass test3
1.4 fail test4
**NOTE: in same cases if you do a "select name from table1 where
number='1.1'" you might get multiple matches, I guess we would need to use
"distinct" ?
I've never interacted two tables before, so I'm not even sure where to start
with this.
I'm using postgres 7.4.
Thanks all.
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: DB question - Merging data from one table to another.
@ 2004-04-05 22:55 scott.marlowe <scott.marlowe@ihs.com>
parent: malia, sean <malia_sean@emc.com>
0 siblings, 0 replies; 2+ messages in thread
From: scott.marlowe @ 2004-04-05 22:55 UTC (permalink / raw)
To: malia, sean <malia_sean@emc.com>; +Cc: pgsql-sql
On Thu, 1 Apr 2004, malia, sean wrote:
> Hello,
>
> I'm not sure if this is even possible, but I'll throw it by you anyway.
>
> Say I have 2 tables:
>
> Table1: With columns number and name
>
> 1.1 test1
> 1.2 test2
> 1.3 test3
> 1.4 test4
>
> Table2: With column number and results
>
> 1.1 pass
> 1.2 fail
> 1.3 pass
> 1.4 fail
>
> What I would like to do is add a new column to Table2 called name and
> populate the name from table 1 and add it to table 2. So, table 2 will look
> like:
>
> 1.1 pass test1
> 1.2 fail test2
> 1.3 pass test3
> 1.4 fail test4
You may want to consider using a view to do this, especially if you don't
have a 1:1 correspondence. I.e. there are a lot of entries in table2 for
1.1 etc...
create view bigview as
select *
from table2 t2
join
table1 t1
on
(t2.number=t1.number);
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2004-04-05 22:55 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2004-04-01 15:27 Re: DB question - Merging data from one table to another. malia, sean <malia_sean@emc.com>
2004-04-05 22:55 ` scott.marlowe <scott.marlowe@ihs.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox