title: Postgres join table: Return only records from one table but with values from others
body: <p>I have a table with ~5,000 records. I have made three join columns in this table. The values in each column are not unique. I want to join to another table (sequentially) by each of these three columns to return values given a condition.</p>
  
  <p>The join table contains multiple columns. Three of these columns are the join columns which will correspond to the first tables' join columns. The join columns in the join table are unique. I want to take the values from the join table and bring to a new column in the first table.</p>
  
  <p>I have a code that I have put together from other suggestions and it runs but I am receiving over 8 million records in the return table. I want the table to only have the records from the first table.</p>
  
  <p>Here is the code:</p>
  
  <pre><code>CREATE TABLE current_condition_joined AS SELECT
    a.id, a.geom, a.condition_join_1, a.condition_join_2, a.condition_join_3,
    coalesce(b.condition, c.condition2, d.condition3) as current_condition, 
    coalesce(b.ecosite, c.ecosite2, d.ecosite3) as current_ecosite,
    coalesce(b.ecophase, c.ecophase2, d.ecophase3) as current_ecophase,
    coalesce(b.consite, c.consite2, d.consite3) as current_consite,
    coalesce(b.conphase, c.conphase2, d.conphase3) as current_conphase
   FROM current_condition a
   LEFT JOIN boreal_mixedwood_labeled b ON a.condition_join_1 = b.label
   LEFT JOIN boreal_mixedwood_labeled c ON a.condition_join_2 = c.label2
   LEFT JOIN boreal_mixedwood_labeled d ON a.condition_join_3 = d.label3
   WHERE b.condition != 'ERROR' and c.condition2 != 'ERROR';
  </code></pre>
  
  <p>I want to get the values from the first join if condition is not ERROR, else the values from the second join if condition is not ERROR, else the values of the third join.</p>
  
  <p>I've looked around, but all examples are asking slightly different things then I am so I can't piece it together.</p>
  
  <p>This is not the same question as: <a href="https://stackoverflow.com/questions/34077833/nested-case-statement-type-error-postgres">Nested Case statement type error (postgres)</a>
  The question asked there was in regard to making a nested statement work. This question is about how the join works. Two different questions, two different posts. </p>