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

table update using result from join

From: Gary Stainburn <gary(dot)stainburn(at)ringways(dot)co(dot)uk>
To: pgsql-sql(at)postgresql(dot)org
Subject: table update using result from join
Date: 2004-10-11 09:49:24
Message-ID: 200410111049.24363.gary.stainburn@ringways.co.uk (view raw or flat)
Thread:
Lists: pgsql-sql
Hi folks.

I'm annoyed that I can't sus out something this simple.

The join below gives the output I want, but I can't work out how to 
convert it to be an update on the requests field.

I want to append the customer name to the fuel (delivery details) field 
and then update the customer field to be 'retail'. but I can't work out 
the description update bit.

goole=# select r.r_fuel||' - Customer: '||c.c_des from requests r, 
customers c
goole-#   where r.r_c_id = c.c_id and c.c_id in (
goole(# 9, 10, 13, 27, 35, 36, 39, 42, 44, 51, 53, 54, 55, 56, 57, 58, 
60, 65, 67, 69,
goole(# 74, 75, 77, 81, 82, 84, 88, 89, 90, 91, 92, 96, 98, 99, 100, 
101, 102, 103,
goole(# 105, 108, 113, 114, 117, 118, 124, 125, 126, 131, 132, 135, 136, 
137, 144,
goole(# 145, 148, 149, 150, 151, 154, 11, 37, 40, 41, 43, 48, 52, 59, 
62,
goole(# 63, 68, 70, 71, 83, 86, 93, 104, 119, 120, 121, 123, 128, 129, 
130,
goole(# 134, 138, 142, 146, 147, 152, 153, 19, 38, 85, 87, 94, 106, 112, 
116,
goole(# 141, 143, 18, 110, 111, 115, 140, 24, 50, 133, 47, 64, 76, 95, 
107,
goole(# 109, 127, 33, 46, 97);
                                      ?column?
-------------------------------------------------------------------------------------
 RINGWAYS - Customer: SUBSCAN
 RINGWAYS - Customer: MARTIN
 ? - Customer: N G BAILEY
 ? - Customer: CHECRON SITE SERVICES LTD
 10 litres - Customer: CONSULTANT SERVICES
 ? - Customer: ALD AUTOMOTIVE
 eskrigg yo19 6ez 9am - Customer: TRANSPORT MANAGEMENT
 TRAILER / PE18 9UH / HALF ON DELIVERY - Customer: ALD AUTOMOTIVE
 DRIVEN / WF16 0NF - Customer: CONSULTANT SERVICES
 TRAILER / HALF TANK ON DELIVERY - Customer: LEX / SWINTON
 DN14 0HR - Customer: CHECRON SITE SERVICES LTD
 . - Customer: other fleet
[snip]
(256 rows)

goole=#

What I want is something like

update requests set r_fuel=<what>, r_c_id = 7 where r_c_id in (.......
-- 
Gary Stainburn
 
This email does not contain private or confidential material as it
may be snooped on by interested government parties for unknown
and undisclosed purposes - Regulation of Investigatory Powers Act, 2000     


pgsql-sql by date

Next:From: Janning VygenDate: 2004-10-11 11:03:37
Subject: Re: How do FKs work?
Previous:From: Harald FuchsDate: 2004-10-11 09:33:55
Subject: Re: Export tab delimited from mysql to postgres.

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group