I'm trying to make a temp logging database. Still on the learnig level.
How do I get the last row from the database?
select * from tempdat order by tdate desc limit 1
gives the first entry of the day but I want the last. See below, it could return the entry whit time 21:25:03
+------------+----------+------+-------------+
| 2014-03-29 | 21:20:02 | inne | 22.875 |
| 2014-03-29 | 21:25:03 | inne | 22.875 |
+------------+----------+------+-------------+
1933 rows in set (0.16 sec)
mysql> select * from tempdat order by tdate desc limit 1;
+------------+----------+------+-------------+
| tdate | ttime | zone | temperature |
+------------+----------+------+-------------+
| 2014-03-29 | 00:00:03 | inne | 21.250 |
+------------+----------+------+-------------+
1 row in set (0.03 sec)
Just use two criteria for ordering: first tdate
, then ttime
. For example:
SELECT *
FROM tempdat
ORDER BY tdate DESC, ttime DESC
LIMIT 1;
Note that order direction should be specified after each column used. ORDER BY tdate, ttime DESC
will first order all the records by tdate ASC
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.