title: How do I write subquery sql for multiple joins
body: <p>Let say there is Part table. 
  I first select Part table with query and it returns 500 rows. 
  After distinct (partid), I get 100 only. </p>
  
  <blockquote>
    <blockquote>
      <p>select count(distinct partid) from Part where partname iLike 'ABC%'; </p>
    </blockquote>
  </blockquote>
  
  <p>Now, I need to loop partid (uniq) , and query 'PartAlt' table to fetch 'alternatepartid'. And this table has 'partid' so I can join. </p>
  
  <p>For each loop, I will get 10 or so but I only need 'alternatepartid' from these rows.</p>
  
  <blockquote>
    <blockquote>
      <p>select alternatepartid from PartAlt where mpnid = xxx 
      So, at the end of loop, I will have 1000 alternatepartid. </p>
    </blockquote>
  </blockquote>
  
  <p>Now, for each loop of these results, I take alternatepartid and join / query with the first 'Part' table above. </p>
  
  <p>So, this is joining a table to get multiple rows in itself. </p>
  
  <p>how do I write this using subquery and/or join ?</p>