title: How to loop select statement based on the previous select statement?
body: <p><a href="https://i.stack.imgur.com/ZiTtU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ZiTtU.png" alt="enter image description here"></a>
  I need all the data to be in one straight line.</p>
  
  <p>I need to create a report and for that i need to summarize all.
  So i did this select statement first.
  <strong>Query1</strong></p>
  
  <pre><code>Select  t1.scn,t1.vsl_name,  t1.act_arr_dt_tm, t1.act_dept_dt_tm, t1.del_remarks
  from vesvoy t1
  </code></pre>
  
  <p>So based on the select statement above i need to get all the <strong>t1.scn</strong> to loop the below sql </p>
  
  <p><strong>Query2</strong></p>
  
  <pre><code>Select  t1.scn,t2.void_flg,
  MAX(case when t2.inv_num like 'VI%' then t2.inv_num end) as Vessel,
  MAX(case when t2.inv_num like 'VI%' then t2.inv_amt end) as Vessel_amt
  from pbosinvoiceitem t1
  inner join pbosinvoice t2 ON t2.id = t1.master_id
  inner join pbosinvtype t4 ON t4.code = t2.inv_type
  group by t1.scn,t2.void_flg
  </code></pre>
  
  <p>so that i can get the result like in the report. I have try to create temp table but the data that i get is all duplicate.</p>
  
  <p>I try combining both queries but the result shows duplicate result</p>