Thread: update from select
Hi folks, don't know if it's cos of the 17 hours I've just worked (sympathy vote please) but I can't get this one worked out I've got table names with nid as name id field and nallowfollow flag. I've got a vehicles table with vowner pointing at nid and a vallowfollow field. How can I update nallowfollow from the appropriate vallowfollow flag? -- 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
On Wed, 29 Oct 2003, Gary Stainburn wrote: > Hi folks, > > don't know if it's cos of the 17 hours I've just worked (sympathy vote please) > but I can't get this one worked out > > I've got table names with nid as name id field and nallowfollow flag. > I've got a vehicles table with vowner pointing at nid and a vallowfollow > field. > > How can I update nallowfollow from the appropriate vallowfollow flag? If vehicles.vowner is unique, something like this maybe (using extensions to sql)? update names set nallowfollow=vehicles.vallowfollowfrom vehicles where vehicles.vowner=names.nid; I think it'd be the follwoing in straight sql: update names set nallowfollow=(select vallowfollow from vehicles where vehicles.vowner=names.nid); If it's not unique, what do you do if there are two vehicles with the same vowner and different values for vallowfollow?
On Wednesday 29 Oct 2003 2:58 pm, Stephan Szabo wrote: > On Wed, 29 Oct 2003, Gary Stainburn wrote: > > Hi folks, > > > > don't know if it's cos of the 17 hours I've just worked (sympathy vote > > please) but I can't get this one worked out > > > > I've got table names with nid as name id field and nallowfollow flag. > > I've got a vehicles table with vowner pointing at nid and a vallowfollow > > field. > > > > How can I update nallowfollow from the appropriate vallowfollow flag? > > If vehicles.vowner is unique, something like this maybe (using extensions > to sql)? > update names set nallowfollow=vehicles.vallowfollow > from vehicles where vehicles.vowner=names.nid; > > I think it'd be the follwoing in straight sql: > update names set nallowfollow= > (select vallowfollow from vehicles where vehicles.vowner=names.nid); > > > If it's not unique, what do you do if there are two vehicles with the same > vowner and different values for vallowfollow? Thanks for this Stephan, although the vowner is not unique, the update has worked sufficantly. Gary > > ---------------------------(end of broadcast)--------------------------- > TIP 6: Have you searched our list archives? > > http://archives.postgresql.org -- 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