Re: Help on update that subselects other records in table, uses joins

Поиск
Список
Период
Сортировка
От Josh Berkus
Тема Re: Help on update that subselects other records in table, uses joins
Дата
Msg-id 200310290942.57584.josh@agliodbs.com
обсуждение исходный текст
Ответ на Help on update that subselects other records in table, uses joins  (Jeff Kowalczyk <jtk@yahoo.com>)
Ответы Re: Help on update that subselects other records in table, uses joins  ("Bryan Encina" <bryan.encina@valleypres.org>)
Список pgsql-sql
Jeff,

> UPDATE ordercharges INNER JOIN orders ON
> orders.orderid = ordercharges.orderid
> SET orderchargeasbilled =

You may only UPDATE one table at a time, you can't update a JOIN.  So when 
selecting from another table to filter or calculate your update, the form is:

UPDATE orderchanges 
SET orderchargesbilled = {expression}
FROM orders
WHERE orders.orderid = ordercharges.orderidAND etc.

Second, your value expression for the update is a subselect which includes a 
select on the table and field you are updating!  This is a recursive loop and 
a very bad idea; gods only know what you'll end up with.

I suggest Joe Conway's "SQL for Smarties"  or "SQL Queries for Mere Mortals" 
from another author.

-- 
Josh Berkus
Aglio Database Solutions
San Francisco


В списке pgsql-sql по дате отправления:

Предыдущее
От: OpenGis
Дата:
Сообщение: Re: Link Oracle tables in Postgre
Следующее
От: Greg Stark
Дата:
Сообщение: Re: Table versions