X-Original-To: pgsql-sql@postgresql.org Received: from spampd.localdomain (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 187714758F1 for ; Thu, 17 Apr 2003 09:20:59 -0400 (EDT) Received: from fzkmail2.fzk.de (fzkmail2.fzk.de [141.52.27.52]) by postgresql.org (Postfix) with SMTP id 8D123475458 for ; Thu, 17 Apr 2003 09:20:57 -0400 (EDT) Received: FROM resy5.fzk.de BY fzkmail2.fzk.de ; Thu Apr 17 15:21:00 2003 +0200 Received: œby rodos.fzk.de with ESMTP (8.8.6 (PHNE_17135)/8.7.1) id PAA20972; Thu, 17 Apr 2003 15:20:59 +0200 (METDST) Message-ID: <3E9EAA3B.DAAE2E86@rodos.fzk.de> Date: Thu, 17 Apr 2003 15:20:59 +0200 From: Christoph Haller X-Mailer: Mozilla 4.77 [en] (X11; U; HP-UX B.10.20 9000/780) X-Accept-Language: en MIME-Version: 1.0 To: pgsql-sql@postgresql.org Cc: mallah@trade-india.com Subject: Re: getting rid of "Adding missing FROM-clause entry...." Content-Type: text/plain; charset=iso-8859-2 Content-Transfer-Encoding: 7bit X-Spam-Status: No, hits=-9.6 required=5.0 tests=BAYES_10,QUOTED_EMAIL_TEXT,QUOTE_TWICE_1 autolearn=ham version=2.50 X-Spam-Level: X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) X-Archive-Number: 200304/263 X-Sequence-Number: 12964 > > Actually i have to update multiple columns my original > query was: > > UPDATE profile_master SET > > title1=a.title1 , fname1=a.fname1 , mname1=a.mname1 , > lname1=a.lname1 , desg1 = a.desg1 FROM > > ( > SELECT company_id , titile as title1 ,fname as fname1 ,mname as mname1 , > lname as lname1 ,company_position as desg1 from public.catalog_key_contacts as b > where b.company_id=profile_master.company_id order by contact_id limit 1 offset 0) > > as a WHERE > > profile_master.source='CATALOG' ; > > > Hi I am having problem with an UPDATE ... FROM > > SQL where the FROM table is a subquery. > > > > UPDATE profile_master set title1=a.title1 FROM > > ( > > > > SELECT company_id , titile as title1 ,fname as fname1 ,mname as mname1 > > ,lname as lname1 ,company_position as desg1 from > > public.catalog_key_contacts where company_id=profile_master.company_id > > order by contact_id limit 1 offset 0 ) as a > > where profile_master.source='CATALOG' ; > > NOTICE: Adding missing FROM-clause entry in subquery for table > > "profile_master" UPDATE 711 > > > > its showing an update of 711 however all the 711 matching rows are getting > > updated to the same value. > > > > can anyone tell me how to write this query properly ? > > I think you need a second reference to the profile_master table. And why are you using "limit 1 offset 0"? So I'd say UPDATE profile_master SET title1=a.title1 , fname1=a.fname1 , mname1=a.mname1 , lname1=a.lname1 , desg1 = a.desg1 FROM ( SELECT company_id , title as title1 ,fname as fname1 ,mname as mname1 , lname as lname1 ,company_position as desg1 from public.catalog_key_contacts as b ,profile_master as c where b.company_id=c.company_id order by contact_id ) as a WHERE source='CATALOG' ; Does this work? Regards, Christoph