Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XCcgL-0005bz-Di for pgsql-sql@arkaria.postgresql.org; Wed, 30 Jul 2014 22:49:13 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1XCcgK-0001wb-U6 for pgsql-sql@arkaria.postgresql.org; Wed, 30 Jul 2014 22:49:12 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1XCcgJ-0001wU-Vb for pgsql-sql@postgresql.org; Wed, 30 Jul 2014 22:49:12 +0000 Received: from sam.nabble.com ([216.139.236.26]) by magus.postgresql.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1XCcgG-000666-4r for pgsql-sql@postgresql.org; Wed, 30 Jul 2014 22:49:10 +0000 Received: from [192.168.236.26] (helo=sam.nabble.com) by sam.nabble.com with esmtp (Exim 4.72) (envelope-from ) id 1XCcgD-0001Mc-Ix for pgsql-sql@postgresql.org; Wed, 30 Jul 2014 15:49:05 -0700 Date: Wed, 30 Jul 2014 15:49:05 -0700 (PDT) From: David G Johnston To: pgsql-sql@postgresql.org Message-ID: <1406760545580-5813364.post@n5.nabble.com> In-Reply-To: <1406760324275-5813363.post@n5.nabble.com> References: <1406760324275-5813363.post@n5.nabble.com> Subject: Re: Reg: Sql Join MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: 0.8 (/) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-sql Precedence: bulk Sender: pgsql-sql-owner@postgresql.org David G Johnston wrote > > CrashBandi wrote >> Hi, >> >> I am having the following question. I am not sure how to approach it. >> Please help! >> >> table A >> name col1 col2 col3 col4 apple 100 11111 1 APL orange 200 22222 3 ORG >> carrot 300 33333 3 CRT >> >> table B >> custom_name value obj_type obj_id apple a FR 100 orange o FR 200 >> carrot >> c VG 300 apple d FR 11111 orange e VG 22222 carrot f UC 33333 apple h >> VG >> 1 orange o FR 3 carrot c VG 3 >> when obj_type ='FR' then join on col1 >> When obj_type='VG' then join on col2 >> When obj_type='UC' then join on col2 >> >> Thanks In advance, >> CB > You cannot do conditional joins in this manner. You will need to write > three joins, one each against a subquery with the appropriate where > clause. > > David J. Actually you might be able to do: On (case obj_type when 'xxx' then col1 when 'yyy' then col2 end = obj_id) But I haven't tried something like this before. David J. -- View this message in context: http://postgresql.1045698.n5.nabble.com/Reg-Sql-Join-tp5813360p5813364.html Sent from the PostgreSQL - sql mailing list archive at Nabble.com. -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql