Received: from localhost (maia-4.hub.org [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id D2B9D9FA440 for ; Thu, 11 Jan 2007 18:02:21 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-new, port 10024) with ESMTP id 07317-05 for ; Thu, 11 Jan 2007 18:02:00 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.4 Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id 85DDD9F9F75 for ; Thu, 11 Jan 2007 18:02:00 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.3 Received: from smtp-vbr8.xs4all.nl (smtp-vbr8.xs4all.nl [194.109.24.28]) by svr4.postgresql.org (Postfix) with ESMTP id 1EFAF5AFA68 for ; Thu, 11 Jan 2007 22:01:58 +0000 (GMT) Received: from [192.168.1.3] (213-84-236-203.adsl.xs4all.nl [213.84.236.203]) (authenticated bits=0) by smtp-vbr8.xs4all.nl (8.13.8/8.13.8) with ESMTP id l0BM1sVr029790; Thu, 11 Jan 2007 23:01:54 +0100 (CET) (envelope-from m.p.dankoor@gmail.com) Message-ID: <45A6B3C6.7000707@gmail.com> Date: Thu, 11 Jan 2007 23:01:42 +0100 From: "M.P.Dankoor" User-Agent: Thunderbird 1.5.0.9 (Windows/20061207) MIME-Version: 1.0 To: devil live Cc: pgsql-sql@postgresql.org Subject: Re: Conditional SQL Query References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-Virus-Scanned: by XS4ALL Virus Scanner X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=1.07 tagged_above=0 required=5 tests=BAYES_50, SPF_NEUTRAL X-Spam-Level: * X-Archive-Number: 200701/35 X-Sequence-Number: 27187 I think that the simplest solution is to use an union e.g: select PRD.product_code ,PRD.product_name ,NULL::int AS production_no ,PTT.stock_code_to_make_product ,PTT.amount from product PRD ,product_tree_template PTT where 1 = 1 AND PRD.product_code = PTT.product_code UNION select PRD.product_code ,PRD.product_name ,PTS.production_no ,PTS.stock_code_to_make_product ,PTS.amount from product PRD ,product_tree_special PTS where 1 = 1 AND PRD.product_code = PTS.product_code ORDER BY 1,2,4 I've added an order by the columns 1,2 and 4 (just guessing), note that this particular solution uses positional ordering, i.e no column names. Mario devil live wrote: > > I want to write sql statement about product, product_tree_special, > product_tree_template > > product has > product_code varchar(20) PRIMARY KEY, > product_name varchar(20) > > product_tree_template has > product_code varchar(20) PK, > stock_code_to_make_product(20) PK, > amout float4 > > product_tree_spcial has > production_no serial, > product_code varchar(20) PK, > stock_code_to_make_product(20) PK, > amout float4 > > > > NOW : product_tree_template table is the default table for production > ingredients of the PRODUCT > > but sometimes my customer using special product_tree table for some > production_no > > how can I write a query to get right ingredients of a product basis on > production_no field > > such as; > > first check production_no if product_tree_special table if not found > then look at template table... > > What are your suggestions? > > > > PS: I do not wanna write PL functions for this... > > Thanks > > _________________________________________________________________ > Hava durumunu bizden ögrenin ve evden öyle çikin! > http://www.msn.com.tr/havadurumu/ > > > ---------------------------(end of broadcast)--------------------------- > TIP 5: don't forget to increase your free space map settings >