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

3 tables join update



Hi,

Say I want to update table Foo with data in table Bar iff left join between Foo and yet another table Baz finds no match.

UPDATE Foo foo LEFT JOIN Bar bar ON (foo.bar_id=bar.id)
SET foo.baz_id=baz.id
FROM Baz baz
WHERE bar.id IS NULL;

ERROR:  syntax error at or near "LEFT"


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;

ERROR:  invalid reference to FROM-clause entry for table "foo"
HINT: There is an entry for table "foo", but it cannot be referenced from this part of the query.



Is it possible to rewrite this so that it does what I want in a single query? Important: performance matters.

Thanks.



Home | Main Index | Thread Index

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