title: Postgresql :joining on fields using CASE expression
body: <p>I am trying to join two tables on two fields with a below condition</p>
  <pre><code>If condition 1 is satisfied then join ON a.field_1 = b.field_1 
  If condition 2 is satisfied then join ON a.field_2 = b.field_2
  </code></pre>
  <p>In order to do so, I am writing the below query</p>
  <pre><code>SELECT 
  a.field_1,a.field_2,
  b.field_1,b.field_2 FROM table a
  INNER JOIN table b
  CASE WHEN COALESCE(TRIM(a.field_1),'') = '' THEN a.field_1 = b.field_1 
  ELSE a.field_2 = b.field_2 END
  </code></pre>
  <p>I am not sure whether this would run.</p>