title: Find Date difference in mysql between two given dates dynamically from a table and count office leave taken by a user
body: <p><a href="https://i.stack.imgur.com/HpBOz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HpBOz.png" alt="Here is the input table"></a></p>
  
  <p>I am trying to finding out No. of sick leaves,personal leaves etc taken by a user.    So I take out Difference of Leave_from &amp; Leave_to column is taken and 1 day is added to the difference result.i.e same day-same day = 0 + 1 day.I take out sum of the leaves days for SICK, for personal etc.</p>
  
  <pre><code>SELECT 
  U.ID,   
  U.FIRSTNAME,
  U.LASTNAME,
  
  L.TITLE,
  
  ULR.LEAVE_TYPE_ID,
  ULR.LEAVE_FROM,
  ULR.LEAVE_TO,
  DATEDIFF(LEAVE_FROM,LEAVE_TO ) AS DiffDate, -- finding date diff dynamically
  SUM(DATE_ADD(DiffDate,INTERVAL 1 DAY)) AS TOTAL LEAVES -- datediff result is added by 1 day and sum of leave day is taken out 
  
  ULR.LEAVE_DESCRIPTION, 
  
  LST.LEAVE_STATUS
  
  
  
  FROM USERS U
  
  LEFT JOIN LEAVE_TYPE L
  ON U.ID = L.ID
  
  LEFT JOIN USERS_LEAVE_REQUEST ULR
  ON U.ID = ULR.USER_ID
  
  LEFT JOIN LEAVE_STATUS_TABLE LST
  
  ON ULR.USER_ID = LST.USER_ID
  </code></pre>