Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id 805B24ADAAC for ; Sat, 10 Dec 2011 12:29:13 -0400 (AST) Received: from nm1-vm1.bullet.mail.ne1.yahoo.com ([98.138.91.36]) by makus.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1RZPnU-00040B-5m for pgsql-sql@postgresql.org; Sat, 10 Dec 2011 16:29:13 +0000 Received: from [98.138.90.50] by nm1.bullet.mail.ne1.yahoo.com with NNFMP; 10 Dec 2011 16:28:59 -0000 Received: from [98.138.88.234] by tm3.bullet.mail.ne1.yahoo.com with NNFMP; 10 Dec 2011 16:28:59 -0000 Received: from [127.0.0.1] by omp1034.mail.ne1.yahoo.com with NNFMP; 10 Dec 2011 16:28:59 -0000 X-Yahoo-Newman-Id: 767478.33090.bm@omp1034.mail.ne1.yahoo.com Received: (qmail 51197 invoked from network); 10 Dec 2011 16:28:59 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=DKIM-Signature:X-Yahoo-Newman-Property:X-YMail-OSG:X-Yahoo-SMTP:Received:References:Mime-Version:In-Reply-To:X-Apple-Yahoo-Original-Message-Folder:Content-Type:Content-Transfer-Encoding:Message-Id:Cc:X-Mailer:From:X-Apple-Yahoo-Replied-Msgid:Subject:Date:To; b=gYkAAdGEr/er/7FlDLSAxc+TD/HsHQRszmncET9m0fEH7B/JrGkDC5sF80MzeuvYld9HHveI9rC72UjSjPmZjww0ukpng+jEw6sVw/Ys5/soQ92oC3M/t1AVDhyE2+JecAF6GFAzRGTvSDu6xiXBr1vyDWYTTT9vJzluUNOoe5s= ; DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1323534539; bh=aJ/ij7YJ75d254SLFsBmkQBeDosSuihc91qT+DG7ing=; h=X-Yahoo-Newman-Property:X-YMail-OSG:X-Yahoo-SMTP:Received:References:Mime-Version:In-Reply-To:X-Apple-Yahoo-Original-Message-Folder:Content-Type:Content-Transfer-Encoding:Message-Id:Cc:X-Mailer:From:X-Apple-Yahoo-Replied-Msgid:Subject:Date:To; b=NkJaEFtuugRI15usg7adM1i5tLK0yPa09G+BxJmD9vjqH3C1oHmXrg/rSCs26Sw2e+i9sR7Eqip56KK/Lwrl04VehnP9I8MSYMc/+pFSKvtYH3f7+TKRWdYp7l3nIWNSufVxFuPzAOn6TRA6L3X7IEvjVYtr7PayNf8csr6QSUw= X-Yahoo-Newman-Property: ymail-3 X-YMail-OSG: oqEVjOcVM1m63jhRucxqFEcdQe.9tO2pXnWD8cKGwl4fmvg gaxEHQL2RHyKDu.y7csMmrkRR4uZHjf42VV6opumtVdOGZ1qL98f2qch.KV8 Qk9ftInsfZmDjp72CCvhM_wFeYqRdCWasV_NQJgvksdkbvtukPkbz4Cr66X5 4k3LGXmI2K9SlYgWJLXVwm36D4GKpEmftvGHRBEfQSYFbMMsTfB3PyeOkC.L HO1P.dNzxPVate5Lc2nLCerPI_B6fRNyvdiLxO5AsCQKHwvASd4Ii2bwNvJO 2wtAVCHgYs.SGv9id94eNEYSzbfEVvYdxQ0nko7o0.T9IVS3BjSPWuQlj4dj Nx4huMJafO6Y3Z5zmEfyx.BNdcZUIMx2kT2pdwA.g1w0qzdCsmzTpVqGL5h3 PXMm2jrA72S0C9MbmIiA19dJHbqTnTyaC X-Yahoo-SMTP: mpGJl6eswBD2IBufoVEg0Pa8gg-- Received: from [10.12.131.94] (polobo@198.228.199.231 with xymcookie) by smtp117-mob.biz.mail.gq1.yahoo.com with SMTP; 10 Dec 2011 08:28:55 -0800 PST References: <20111210170332479879.3df30525@klingler.net> Mime-Version: 1.0 (iPad Mail 8J2) In-Reply-To: <20111210170332479879.3df30525@klingler.net> X-Apple-Yahoo-Original-Message-Folder: Inbox Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-Id: <2BBB44CA-7EFA-4084-906F-6CB72AD28C6E@yahoo.com> Cc: "pgsql-sql@postgresql.org" X-Mailer: iPad Mail (8J2) From: David Johnston X-Apple-Yahoo-Replied-Msgid: 1_712018_APCkiGIAANWnTuODAgb9sgpkSbQ Subject: Re: conditional FROM Date: Sat, 10 Dec 2011 11:28:29 -0500 To: Richard Klingler X-Pg-Spam-Score: -1.1 (-) X-Archive-Number: 201112/39 X-Sequence-Number: 36100 On Dec 10, 2011, at 11:03, Richard Klingler wrote: > Good day... > > I'm trying to build a query for PGSQL 9.1 where a table has two > references with only one being used depending of the type of entry.. > > For example, the table has following simplified structure: > > portid primary key > port2node index to table node > port2card index to table card > > So how can I do a conditional FROM clause in the query depending on the > column port2node and port2card? > If port2card is Null or 0 I don't want it in the FROM clause as the > query will return unneccessary duplicate > row...the same goes for port2node being Null or 0... > > > thanx in advance > richard > > Two options (one of which may not work for you). 1. Write two queries, one for each table, and union the results. 2. Use LEFT JOINs (somehow...) David J.