Re: Conditional Lookup Table with Like

From: sqlQuestions <ryanpgodfrey(at)gmail(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: Conditional Lookup Table with Like
Date: 2017-02-16 23:05:48
Message-ID: 1487286348488-5944801.post@n3.nabble.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-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.

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message David G. Johnston 2017-02-16 23:32:38 Re: Conditional Lookup Table with Like
Previous Message David G. Johnston 2017-02-16 22:37:30 Re: Conditional Lookup Table with Like