X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id C24EB329E2C for ; Thu, 9 Sep 2004 21:05:56 +0100 (BST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 74051-09 for ; Thu, 9 Sep 2004 20:05:51 +0000 (GMT) Received: from news.hub.org (news.hub.org [200.46.204.72]) by svr1.postgresql.org (Postfix) with ESMTP id 1F7FD329E12 for ; Thu, 9 Sep 2004 21:05:52 +0100 (BST) Received: from news.hub.org (news.hub.org [200.46.204.72]) by news.hub.org (8.12.9/8.12.9) with ESMTP id i89K5mCn077675 for ; Thu, 9 Sep 2004 20:05:49 GMT (envelope-from news@news.hub.org) Received: (from news@localhost) by news.hub.org (8.12.9/8.12.9/Submit) id i89Js4Rd073715 for pgsql-sql@postgresql.org; Thu, 9 Sep 2004 19:54:04 GMT From: Collin Peters User-Agent: Mozilla Thunderbird 0.7.3 (Windows/20040803) X-Accept-Language: en-us, en MIME-Version: 1.0 X-Newsgroups: comp.databases.postgresql.sql Subject: Using UPDATE FROM Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Lines: 44 Message-ID: Date: Thu, 09 Sep 2004 19:54:05 GMT To: pgsql-sql@postgresql.org X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200409/80 X-Sequence-Number: 18926 I have a sql query which hits 5 database tables. I'll cut a bit out of the results and just show the important values reps_goal reps_actual repsvalue 10 10 1 33 5 1 10 12 1 10 12 1 10 10 1 11 11 1 What I'm trying to do is a single UPDATE statement which will take the values from the reps_actual column, and put them into the repsvalue column. These two columns come from different tables or obviously you could to a simple regular UPDATE. Here is the UPDATE statement: UPDATE programactivitysets SET repsvalue = reps_actual FROM workouts w, workoutactivities wa, workoutactivitysets was, programactivities pa, programactivitysets pas WHERE wa.workout_id = w.workout_id AND was.workoutactivity_id = wa.workoutactivity_id AND pa.programactivity_id = wa.programactivity_id AND pas.programactivity_id = pa.programactivity_id AND pas.set = was.set AND w.workout_id = 6036; After I run that and do a select, these are the results: reps_goal reps_actual repsvalue 10 10 5 33 5 5 10 12 5 10 12 5 10 10 5 11 11 5 For some reason, repsvalue is assigned 5 which is the reps_actual value for the 2nd row. This isn't right. Am I doing something incorrectly or can postgres not handle this kind of UPDATE? Regards, Collin Peters