title: Select from a table based on another table Number of records Oracle
body: <p>I have a unique requirement to select records from one table based on another table only if the second table has at least one record with a certain flag. The query should not return two records for the same ID: example:
  Table 1</p>
  
  <pre><code>id  name    location
  4   myname  MyLocation
  6   hisname HisLocation
  7   hername herlocation
  </code></pre>
  
  <p>The id in this table are unique:
  Table two</p>
  
  <pre><code>id  details1   details2    closureflg
  4   somdetails somedetails  Y
  4   somdetails somedetails  Y
  6   somdetails somedetails  N
  7   somdetails somedetails  N
  7   somdetails somedetail   N
  </code></pre>
  
  <p>I need to select from the first table one record only as long as the corresponding id has records in Table 2 whose closure flag is N:</p>
  
  <p>I have tried:</p>
  
  <pre><code>select * from table1 where id in(select id from tbale2 where closureflg = 'N');
  </code></pre>
  
  <p>this returns two records for id 7;</p>
  
  <p>My expected output:</p>
  
  <pre><code>id  name    location
  6   hisname HisLocation
  7   hername herlocation.
  </code></pre>
  
  <p>Please help.</p>