select row from table and substitute a field with one from another column if not null

Posted by EarthMind on Stack Overflow See other posts from Stack Overflow or by EarthMind
Published on 2010-06-09T13:48:38Z Indexed on 2010/06/09 13:52 UTC
Read the original article Hit count: 156

Filed under:
|
|
|
|

I'm trying construct a PostgreSQL query that does the following but so far my efforts have been in vain.

Problem: There are two tables: A and B. I'd like to select all columns from table A (having columns: id, name, description) and substitute the "A.name" column with the value of the column "B.title" from table B (having columns: id, table_A_id title, langcode) where B.table_A_id is 5 and B.langcode is "nl" (if there are any rows).

I've tried using a CASE and COALESCE() but failed due to my inexperience with both concepts.

Thanks in advance.

© Stack Overflow or respective owner

Related posts about sql

Related posts about postgresql