【发布时间】:2015-02-03 04:45:42
【问题描述】:
我有一个表,其中包含带有时间戳的记录。现在我需要获取最旧的记录和最新的记录
9/10/2014 6:54
9/10/2014 6:53
9/10/2014 6:51
9/8/2014 8:09
9/8/2014 7:00
9/5/2014 7:38
9/5/2014 3:57
9/5/2014 3:51
9/4/2014 11:09
9/4/2014 8:39
目前这是我通过发送两个会减慢处理速度的数据库调用来获取它们的方式
$new_timestamp = mysql_query("SELECT TIMESTAMP FROM $rectable ORDER BY TIMESTAMP DESC LIMIT 1");
$col_old = mysql_fetch_assoc($new_timestamp);
$old = $col_new['TIMESTAMP'];
$new_timestamp1 = mysql_query("SELECT TIMESTAMP FROM $rectable ORDER BY TIMESTAMP ASC LIMIT 1");
$col_new = mysql_fetch_assoc($new_timestamp1);
$new = $col_new['TIMESTAMP'];
有什么方法可以优化此代码和满足要求,而无需通过特殊查询或存储过程发送两个数据库调用
【问题讨论】:
标签: php mysql sql stored-procedures