title: Convert multiples row into one rows based on master key
body: <p>I have following records on my table. I want to convert these records into one single row based on master key. </p>
  
  <pre><code>records:-
  id     date        userkey workinghours  masterkey
  1941   2016-06-01    1         6           NULL
  1946   2016-06-08    1         1           NULL
  1947   2016-06-09    1         6           1946
  1948   2016-06-10    1         3           1946
  </code></pre>
  
  <p>I want output like this.</p>
  
  <pre><code>id     startdate   endate     userkey workinghours  masterkey
  1941   2016-06-01  2016-06-01    1      6            NULL
  1946   2016-06-08  2016-06-10    1      10           1946
  </code></pre>
  
  <p>How can i do this ? As a newbie I need your help to write this query.</p>