How do I add a COALESCE to a db_select? I want to achieve the following query using db_select():

SELECT 
  Column1, 
  Column2, 
  COALESCE(Column1, Column2) AS Column3 
FROM TEST_ATTRIBUTES


How do I add the coalesced column to the query?

Thank you
You can add an expression:

$query = db_select('TEST_ATTRIBUTES', 't')
  -&gt;fields('t', array('Column1', 'Column2'));

$query-&gt;addExpression('COALESCE(Column1, Column2)', 'Column3');


The above yields:

SELECT  
  t.Column1 AS Column1, 
  t.Column2 AS Column2, 
  COALESCE(Column1, Column2) AS Column3
FROM TEST_ATTRIBUTES t