agora inbox for pgsql-sql@postgresql.org  
help / color / mirror / Atom feed
From: sqlQuestions <ryanpgodfrey@gmail.com>
To: pgsql-sql@postgresql.org
Subject: Re: Conditional Lookup Table with Like
Date: Thu, 16 Feb 2017 16:05:48 -0700 (MST)
Message-ID: <1487286348488-5944801.post@n3.nabble.com> (raw)
In-Reply-To: <CAKFQuwYpF146ygOUSXSsAxdAKGsSUXt=a5HtRpUQT=YTy+mwkw@mail.gmail.com>
References: <1487283597419-5944796.post@n3.nabble.com>
	<CAKFQuwYpF146ygOUSXSsAxdAKGsSUXt=a5HtRpUQT=YTy+mwkw@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-sql>

Thanks for your response David.

I took out the WHEN table2.category IS NULL clause because I only want it to
pull the category from table2 when the lookup_value exists in description,
otherwise pull the table1 category. NULL doesn't matter to me.

Unfortunately, it still always pulls the category from table1.

SELECT code, description,
CASE WHEN description LIKE ('%' || lookup_value || '%')
          THEN table2.category
          ELSE table1.category
           END
FROM table1
LEFT JOIN table2 USING (code);



--
View this message in context: http://postgresql.nabble.com/Conditional-Lookup-Table-with-Like-tp5944796p5944801.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



view thread (9+ messages)  latest in thread

Message-ID: <1487286348488-5944801.post@n3.nabble.com>
Permalink:  ../1487286348488-5944801.post@n3.nabble.com/
Also on:    postgresql.org/message-id/1487286348488-5944801.post@n3.nabble.com

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: ryanpgodfrey@gmail.com
  Subject: Re: Conditional Lookup Table with Like
  In-Reply-To: <1487286348488-5944801.post@n3.nabble.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox