- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Display record with most recent time in MySQL
You can use ORDER BY STR_TO_DATE(). Let us first create a table −
mysql> create table DemoTable -> ( -> DueTime varchar(20) -> ); Query OK, 0 rows affected (0.87 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('7:30AM'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('9:00PM'); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable values('11:00PM'); Query OK, 1 row affected (0.13 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable;
This will produce the following output−
+---------+ | DueTime | +---------+ | 7:30AM | | 9:00PM | | 11:00PM | +---------+ 3 rows in set (0.00 sec)
Here is the query to fetch records with most recent time −
mysql> select * from DemoTable -> order by str_to_date(DueTime, '%h:%i%p') desc limit 1;
This will produce the following output −
+---------+ | DueTime | +---------+ | 11:00PM | +---------+ 1 row in set (0.00 sec)
- MySQL query to get the last created table name (most recent)?
- Display record with today and tomorrow’s date from a column with date record in MySQL
- Display only a specific duplicate record in MySQL
- How can we find the most recent and most oldest date from a table with the help of MySQL MAX() and MIN() functions?
- How do I select 5 random rows from the 20 most recent rows in MySQL?
- How to select most recent date out of a set of several possible timestamps in MySQL?
- MongoDB query to select 10 most recent documents without changing order?
- Display all records ignoring the current date record in MySQL
- Display the record with non-duplicate Id using MySQL GROUP BY and HAVING
- How to find the most recent file in a directory on Linux?
- MySQL query to display record with maximum count values in a group with other column values?
- Implement specific record ordering with MySQL
- Display distinctly ordered MongoDB record with skip and limit?
- How to get the color of the most recent plotted line in Python?
- MySQL query to search record with apostrophe?