title: Limiting result sets by future date - SQL
body: <p>The Query below produces a record for each Entry in the SP_ScheduleEvent Table.</p>
  
  <pre><code> SELECT m.MaterialId,  m.MaterialTitle, se.EventDateTime, c.ChannelName
      FROM GB_Material m
      LEFT OUTER JOIN SP_ScheduleEvent se on se.MaterialName = m.MaterialName
      INNER JOIN SP_Schedule s on s.ScheduleID = se.ScheduleID
      INNER JOIN GB_Channel c on c.ChannelID = s.ChannelID
      WHERE LOWER(m.MaterialName) like '%foo%' OR LOWER(m.MaterialTitle) like '%foo%'
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/kGOnS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kGOnS.png" alt="enter image description here"></a></p>
  
  <p>I want to limit the result set by the nearest future EventDateTime.</p>
  
  <p>So per material name i would like to see one EventDateTime, which should be the nearest future date to the current time. </p>
  
  <p>And lastly, a record may not exist in the SP_ScheduleEvent table for a particular materialname, in which case there should be null returned for the EventDateTime column</p>
  
  <p><a href="http://sqlfiddle.com/#!6/e2d5e" rel="nofollow noreferrer">SQLFiddle</a></p>
  
  <p>How would i go about doing this?</p>