Re: Conditional Lookup Table with Like

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: sqlQuestions <ryanpgodfrey(at)gmail(dot)com>
Cc: "pgsql-sql(at)postgresql(dot)org" <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Conditional Lookup Table with Like
Date: 2017-02-16 23:32:38
Message-ID: CAKFQuwbdNiN=-ij7Lz0gc6XRwe2cPoVKyc+WH-Z_9+7FR=yj5g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Thu, Feb 16, 2017 at 4:05 PM, sqlQuestions <ryanpgodfrey(at)gmail(dot)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.​

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message sqlQuestions 2017-02-17 00:37:04 Re: Conditional Lookup Table with Like
Previous Message sqlQuestions 2017-02-16 23:05:48 Re: Conditional Lookup Table with Like