From: | Alban Hertroys <dalroi(at)solfertje(dot)student(dot)utwente(dot)nl> |
---|---|
To: | John Smith <jayzee(dot)smith(at)gmail(dot)com> |
Cc: | PostgreSQL General <pgsql-general(at)postgresql(dot)org>, mabewlun(at)gmail(dot)com, depesz(at)depesz(dot)com |
Subject: | Re: update ... set ... subquery |
Date: | 2010-03-17 23:06:03 |
Message-ID: | 96DC5241-7A7B-45F8-8A1E-13F6CC10D33E@solfertje.student.utwente.nl |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On 17 Mar 2010, at 21:40, John Smith wrote:
> guys,
> sorry my query is like so:
> update a
> set number = any ( select number from b where a.name=b.name )
> where number is null;
>
Looks like you want:
update a
set number = b.number
from b
where number is null
and name = b.name;
> simplified table a:
> sn | number | name
> ----------------------------------
> 1 | 101 | john
> 2 | null | mary
> 3 | 127 | mark
> 4 | null | jane
> 5 | 133 | matt
>
> simplified table b:
> sn | number | name
> ----------------------------------
> 1 | 101 | john
> 2 | 967 | mary
> 3 | 127 | mark
> 4 | 965 | jane
> 5 | 133 | matt
>
> so basically trying to get "number" from "b" to "a" where their "name"s match.
>
> also "... number in (...) ..." throws error (syntax error at or near "in").
> thks, jzs
Alban Hertroys
--
If you can't see the forest for the trees,
cut the trees and you'll see there is no forest.
!DSPAM:737,4ba1607e10411836611115!
From | Date | Subject | |
---|---|---|---|
Next Message | Miguel Angel Hernandez Moreno | 2010-03-17 23:27:41 | Re: recuperar nodo en estado 3 |
Previous Message | John Smith | 2010-03-17 20:40:17 | Re: update ... set ... subquery |