title: Get the one row from rows from the multiple column value using sql join
body: <p>we have an id table as following</p>
  
  <pre><code>id  |  newsecid
  --- |  ---
  1   |    10
  2   |    20
  3   |    30
  </code></pre>
  
  <p>The single id will have single newsecid </p>
  
  <p>Another table is feat</p>
  
  <pre><code>id  |  featid
  --- |  ---
  1   |  5
  1   |  6
  2   |  2
  2   |  4
  </code></pre>
  
  <p>One id can have multiple feat ids</p>
  
  <p>reference table</p>
  
  <pre><code>newsecid  |  featid  |  oldsecid
  ---       |  ---     |  .            
  6         |  null    |  2
  2         |  null    |  6
  3         |  null    |  5  
  1         |  NULL    |  1
  1         |  5       |  4
  16        |  NULL    |  16
  16        |  4       |  13
  25        |  NULL    |  26
  25        |  6       |  25
  26        |  NULL    |  26
  26        |  6       |  24
  </code></pre>
  
  <p>When there are multiple featids for the same id we consider them as null to join with the ref tables  </p>
  
  <p>For all the newsecids there is no need for the combination of newsecid and featid to get the oldsecid from the ref table because there is always only one value like in the case of newsecids as 6,2 and 3 with featid as null.</p>
  
  <p>But for only newsecids 1,16,25,26 we have to pick oldsecid from the combination of newsecid and featid from the ref table as there are 2 values for that.One with null featid and one with some featid value.</p>
  
  <p>The cases where there is no requirement for the combination I am using</p>
  
  <pre><code>select c.oldsecid from id i
  inner join feat f on i.id=f.id
  inner join ref c  on i.newsecid = c.newsecid
  </code></pre>
  
  <p>Using this I am getting oldsecid 2,6,5 from the ref table since there is only one value.</p>
  
  <p>For the cases 1,16,25,26 using the above query I am getting random oldsecid . In this, I need that oldsecid where featid is not null.</p>
  
  <p>We can hardcode the condition of newsecid for 1,16,25,26 as I don't have only these cases only.  </p>