title: Postgresql joining one column with 2 not null columns
body: <p>I have 2 tables that I want match by ID.</p>
  
  <p>EDIT: Table1:</p>
  
  <pre><code>    | id  | other columns A |
      | 23  |   ...           |
      | 27  |   ...           |
      | 9   |   ...           | 
      | 50  |   ...           | 
  </code></pre>
  
  <p>Table2:</p>
  
  <pre><code>| id_new  | id_old | other columns B
  | 23      |   7    | ...
  | 27      |   8    | ...
  | 33      |   9    | ...
  </code></pre>
  
  <p>Problem is that the second table contains 2 ID columns: first with new ID second with the old one - both can match the ID from first table.</p>
  
  <p>EDIT: there are some rows from table A which ID not match neither id_new nor id_old. But I want them to retain in the new table. </p>
  
  <p>This is my desired result:</p>
  
  <pre><code>     | id  | id_new | id_old | other columns A + B
       | 23  |  23    |   7    |  A + B
       | 27  |  27    |   8    |  A + B
       | 9   |  33    |   9    |  A + B 
       | 50  |  --    |   --   |  A
  </code></pre>
  
  
  
  <p>I tried this one but it's a huge dataset and my query takes a long time to execute. </p>
  
  <pre><code>create table spoj2 
  as 
      select * 
      from table1 
      left join table2   on table1.id = table2.id_new 
                         or table1.id = table2.id_old
  </code></pre>