title: SQL: How to select one record per day, assuming that each day contain more than 1 value MySQL
body: <p>I want to select records from <code>'2013-04-01 00:00:00'</code> to <code>'today'</code> but, each day has lot of value, because they are saving each 15 minutes a value, so I want only the first or last value from each day.</p>
  
  <p>Table schema:</p>
  
  <pre><code>CREATE TABLE IF NOT EXISTS `value_magnitudes` (
    `id` int(11) NOT NULL AUTO_INCREMENT,
    `value` float DEFAULT NULL,
    `magnitude_id` int(11) DEFAULT NULL,
    `sdi_belongs_id` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
    `reading_date` datetime DEFAULT NULL,
    `created_at` datetime DEFAULT NULL,
    `updated_at` datetime DEFAULT NULL,
    PRIMARY KEY (`id`)
  ) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1118402 ;
  </code></pre>
  
  <p>Bad SQL:</p>
  
  <pre><code>SELECT value FROM `value_magnitudes` WHERE `value_magnitudes`.`reading_date` BETWEEN '2013-04-01 00:00:00' AND '2013-04-02 00:00:00' AND (`value_magnitudes`.magnitude_id = 234) LIMIT 1
  SELECT value FROM `value_magnitudes` WHERE `value_magnitudes`.`reading_date` BETWEEN '2013-04-02 00:00:00' AND '2013-04-03 00:00:00' AND (`value_magnitudes`.magnitude_id = 234) LIMIT 1
  SELECT value FROM `value_magnitudes` WHERE `value_magnitudes`.`reading_date` BETWEEN '2013-04-03 00:00:00' AND '2013-04-04 00:00:00' AND (`value_magnitudes`.magnitude_id = 234) LIMIT 1
  SELECT value FROM `value_magnitudes` WHERE `value_magnitudes`.`reading_date` BETWEEN '2013-04-04 00:00:00' AND '2013-04-05 00:00:00' AND (`value_magnitudes`.magnitude_id = 234) LIMIT 1
  SELECT value FROM `value_magnitudes` WHERE `value_magnitudes`.`reading_date` BETWEEN '2013-04-05 00:00:00' AND '2013-04-06 00:00:00' AND (`value_magnitudes`.magnitude_id = 234) LIMIT 1
  etc ...
  </code></pre>
  
  <p>I want all in one if possible...</p>
  
  <p>Thank you a lot.</p>
  
  <p><strong>EDIT:</strong>
  I mean, I have a query per day, but I just want to make a single query from <code>reading_date &gt;= '2013-04-01 00:00:00'</code>c</p>
  
  <p><strong>EDIT2:</strong>
  I have <strong>64,260</strong> records in that <code>table.value_magnitudes</code> and it takes sooooooooo long to excecute and response that query, and sometimes timeout conection.</p>