Skip site navigation (1) Skip section navigation (2)

Peripheral Links

Header And Logo

PostgreSQL
| The world's most advanced open source database.

Site Navigation

Search for
  Advanced Search

Re: 3 tables join update



--- rihad <rihad(at)mail(dot)ru> wrote:
> UPDATE Foo foo
> SET foo.baz_id=baz.id
> FROM Baz baz LEFT JOIN Bar bar ON (foo.bar_id=bar.id)
> WHERE bar.id IS NULL;

This query cannot work.  Basiclly, you are trying to set the foo.baz_id = baz.id for records in
foo that do not yet exist.  Doing this is impossible.

For this to work, you should be using an INSERT query to _ADD_ records to foo that do not yet
exist.

Regards,
Richard Broersma Jr.





Home | Main Index | Thread Index

Privacy Policy | PostgreSQL Archives hosted by Command Prompt, Inc. | Designed by tinysofa
Copyright © 1996 – 2008 PostgreSQL Global Development Group