title: Grab value based on column value
body: <p>this is my table:</p>
  
  <pre><code>    idMission Event               Timestamp
      1         detectedBubbleOut 2018-05-26T12:53:43.000Z
      1         arrived               2018-05-26T13:58:57.000Z
      1         detectedInBuilding    2018-05-26T12:42:20.000Z
      1         detectedBubbleIn  2018-05-26T12:37:36.000Z
      1         detectedTimeOut       2018-05-26T12:52:17.000Z
      1         scanFulfilled     2018-05-26T12:41:26.000Z
      1         detectedBubbleIn  2018-05-26T12:37:22.000Z
      1         customerInteraction   2018-05-26T13:59:04.000Z
      1         scanFulfilled     2018-05-26T13:59:01.000Z
      1         delFulfilled      2018-05-26T12:48:30.000Z
      1         eventFulfilled        2018-05-26T12:48:30.000Z
      1         nextDelivery      2018-05-26T12:50:20.000Z
      1         customerInteraction   2018-05-26T12:48:18.000Z
      1         detectedOutBuilding   2018-05-26T12:49:21.000Z
      1         arrived               2018-05-26T12:40:09.000Z
      1         detectedTimeIn        2018-05-26T12:38:58.000Z
      2         nextDelivery          2018-05-27T12:50:20.000Z
      2         customerInteraction   2018-05-27T12:48:18.000Z
      2         detectedOutBuilding   2018-05-27T12:49:21.000Z
      2         arrived               2018-05-27T12:40:09.000Z
      2         detectedTimeIn        2018-05-27T12:38:58.000Z
  </code></pre>
  
  <p>There are some events associated with a timestamp, this is when the event happens. I'm focusing on the events "arrived" and "detectedTimeIn", but the event "detectedTimeIn" is not always available so i use "arrived". 
  All i want is to grab the timestamp  based on specific event.
  If  the event "detectedTimeIn" exists then i grab its timestamp, if it does not exists then i'll grab the timestamp of the event "arrived".
  This is what i've achieved so far:</p>
  
  <pre><code>    select 
          event,
          stp."timestamp" as TimeIN
      from main_source_execevent_coop stp
      where event Coalesce('detectedTimeIn', 'arrived')
  </code></pre>
  
  <p>EXPECTED RESULTS:</p>
  
  <pre><code>1         detectedTimeIn        2018-05-26T12:38:58.000Z
  2         arrived               2018-05-27T12:40:09.000Z
  </code></pre>
  
  <p>But it's not working i obtain only:
  1         detectedTimeIn        2018-05-26T12:38:58.000Z</p>
  
  <p>Ignoring the "arrived" row.
  Have you any suggestion?</p>
  
  <p>Thanks</p>