title: SQL - nested select queries
body: <p><img src="https://i.stack.imgur.com/R61hi.jpg" alt="DATA SETS"></p>
  
  <p>I want to select all <code>dealercode</code> (distinct) and <code>introducercode</code> with iapn. Bbut iapn must be a highest value only.</p>
  
  <p>e.g. </p>
  
  <pre><code>dealercode = 7 and iapin = 3 and introducercode = 3 
  </code></pre>
  
  <p>like that (THIS MUST BE A ONLY VALUE FOR DEALERCODE)</p>
  
  <p>This is my query:</p>
  
  <pre><code>  SELECT DISTINCT 
        dealercode, iapin as iapin,
        (SELECT introducercode) as introducecode
    FROM 
        dealerplacement d
    where 
        exists (SELECT MIN(iapin) FROM dealerplacement )
    ORDER BY 
        dealercode, iapin ASC 
  </code></pre>
  
  <p>I have attached with this post data set to this code. </p>
  
  <p><img src="https://i.stack.imgur.com/5Itma.jpg" alt="enter image description here"></p>
  
  <p>This is the structure. I want to get result as below.
         DEALERCODE 1200 iapn 003 and introducercode 203.   only.</p>
  
  <p>current database as below.</p>
  
  <pre><code>  1200  001  201
    1200  002  202
    1200  003  203
  </code></pre>
  
  <p>Please help me to solve this.</p>