title: Update the first row of table via sql
body: <p>I have a base table per_name :</p>
  
  <pre><code>start_date   end_date        type      name person_id 
  
  01-jan-2016  02-Feb-2016      A         abc     1
  03-Feb-2016  31-Dec-412       E         abc     1
  </code></pre>
  
  <p>Per_leg_data</p>
  
  <pre><code>start_date     end_date       leg_code    person_id 
  31-Nov-2015    03-Mar-2016     SG            1
  04-Mar-2016    31-Dec-4712     CG            1
  </code></pre>
  
  <p>Now what i want is that whenever the min(start_date) of name &lt;>min(start_date) of leg_data then the first row of per_leg_data should be replaced by per_name min(start_date)</p>
  
  <p>Something like :</p>
  
  <pre><code>If min(name.start_date) &lt;&gt; min(leg.start_date) 
  then
  update per_leg_data
  set start_date = (select distinct min(start_date)
   from per_name pn 
  where pn.person_id=person_id)
  </code></pre>
  
  <p>But this updating all the rows of the per_leg_data of date_start</p>