Re: [SQL] Conditional Lookup Table with Like - Mailing list pgsql-sql

From David G. Johnston
Subject Re: [SQL] Conditional Lookup Table with Like
Date
Msg-id CAKFQuwbdNiN=-ij7Lz0gc6XRwe2cPoVKyc+WH-Z_9+7FR=yj5g@mail.gmail.com
Whole thread Raw
In response to Re: [SQL] Conditional Lookup Table with Like  (sqlQuestions <ryanpgodfrey@gmail.com>)
Responses Re: [SQL] Conditional Lookup Table with Like  (sqlQuestions <ryanpgodfrey@gmail.com>)
Re: [SQL] Conditional Lookup Table with Like  (sqlQuestions <ryanpgodfrey@gmail.com>)
List pgsql-sql
On Thu, Feb 16, 2017 at 4:05 PM, sqlQuestions <ryanpgodfrey@gmail.com> wrote:
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);


​If you provide a self-contained example with records you expect and don't expect to match better help can be given.

David J.​

pgsql-sql by date:

Previous
From: sqlQuestions
Date:
Subject: Re: [SQL] Conditional Lookup Table with Like
Next
From: sqlQuestions
Date:
Subject: Re: [SQL] Conditional Lookup Table with Like