title: MySQL - Select the least day of the current month/year, not necessarily the first day of the month
body: <p>Using PHP/MySQL</p>
  
  <p>I'm trying to create a select statement that gets the data from the least day of the current month and year (I'm using it to show data from on a certain player 'this month').  The 1st of the months data may not always exist therefore if the first isn't found then it would use the 2nd or 3rd or so on, whichever is the least month.</p>
  
  <p>The query would need to be something like: </p>
  
  <pre><code>SELECT * FROM table_name WHERE name = '$username' AND
  [...theDate = the least day of data in the current month/year]
  </code></pre>
  
  <p>It would return a single row of data.</p>
  
  <p>This is a query I use for getting the 'this week' data:</p>
  
  <pre><code>SELECT name, data, theDate
  FROM table_name
  WHERE name = '$username'
  AND YEARWEEK(theDate) = YEARWEEK(CURRENT_DATE)
  ORDER BY theDate;
  </code></pre>