From: | John R Pierce <pierce(at)hogranch(dot)com> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Insert data in two columns same table |
Date: | 2016-03-17 02:19:03 |
Message-ID: | 56EA1417.1020502@hogranch.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On 3/16/2016 7:07 PM, drum(dot)lucas(at)gmail(dot)com wrote:
>
> *1 -* select the billable_id: (SELECT1)
> SELECT billable_id FROM junk.wm_260_billables2 WHERE info ilike '%Alisha%'
>
> *2 -* select the mobiuser_id: (SELECT2)
> SELECT id FROM public.ja_mobiusers WHERE name_first LIKE 'Alisha%' AND
> name_last LIKE 'Dadryl%'
>
> *3 -* Insert those two data into the dm.billables_links table (EXAMPLE):
> INSERT INTO dm.billables_links (billable_id, mobiuser_id) VALUES
> (SELECT1, SELECT2);
assuming those two queries 1 and 2 return multiple rows, which rows of
junk.wm_260_billables2 match up with what rows of public.ja_mobiusers ?
your schema is very poorly defined. I think you need to take a class in
relational database design and usage, or read a good book on it at least..
the *CORRECT* SOLUTION WOULD BE MORE LIKE
INSERT INTO dm.billables_links (billable_id, mobiuser_id) SELECT
b.billable_id, m.id from billables b inner join ja_mobiusers m on
b.billable_id = ... where ......
I left ... in because your code fragments are referencing fields that
aren't even IN your tables, and your tables don't have sane references.
--
john r pierce, recycling bits in santa cruz
From | Date | Subject | |
---|---|---|---|
Next Message | Andreas Kretschmer | 2016-03-17 02:26:24 | Re: Insert data in two columns same table |
Previous Message | David G. Johnston | 2016-03-17 02:16:03 | Re: Insert data in two columns same table |