
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
MySQL command to order timestamp values in ascending order without using TIMESTAMP()?
You can use ORDER BY ASC to order timestamp values in ascending order.
The following is the syntax without using TIMESTAMP() −
SELECT yourTimestampColumnName from yourTableName order by yourTimestampColumnName ASC;
To understand the above syntax, let us create a table. The query to create a table is as follows −
mysql> create table Timestamp_TableDemo -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> yourTimestamp timestamp -> ); Query OK, 0 rows affected (0.83 sec)
Now you can insert some records in the table using insert command. The query is as follows −
mysql> insert into Timestamp_TableDemo(yourTimestamp) values('2019-02-06 17:34:57'); Query OK, 1 row affected (0.14 sec) mysql> insert into Timestamp_TableDemo(yourTimestamp) values('2019-02-06 17:32:30'); Query OK, 1 row affected (0.25 sec) mysql> insert into Timestamp_TableDemo(yourTimestamp) values('2019-02-06 17:32:09'); Query OK, 1 row affected (0.14 sec)
Now you can display all records from the table using a select statement. The query is as follows −
mysql> select *from Timestamp_TableDemo;
The following is the output −
+----+---------------------+ | Id | yourTimestamp | +----+---------------------+ | 1 | 2019-02-06 17:34:57 | | 2 | 2019-02-06 17:32:30 | | 3 | 2019-02-06 17:32:09 | +----+---------------------+ 3 rows in set (0.00 sec)
Here is the query to order timestamp values in ascending order −
mysql> select yourTimestamp from Timestamp_TableDemo -> order by yourTimestamp ASC;
The following is the output −
+---------------------+ | yourTimestamp | +---------------------+ | 2019-02-06 17:32:09 | | 2019-02-06 17:32:30 | | 2019-02-06 17:34:57 | +---------------------+ 3 rows in set (0.00 sec)
- Related Articles
- MySQL command to order timestamp values in ascending order?
- How to order by timestamp in MySQL?
- MySQL query to order timestamp in descending order but place the timestamp 0000-00-00 00:00:00 first?
- How to order by timestamp (descending order) in MongoDB
- Convert MySQL timestamp to UNIX Timestamp?
- MySQL Order by a specific column x and display remaining values in ascending order
- How to get timestamp using MySQL?
- Order MySQL records randomly and display name in Ascending order
- How to convert from Unix timestamp to MySQL timestamp value?
- Order MySQL results without identifier?
- MySQL ORDER BY with EXPLAIN command
- How can we sort MySQL output in ascending order?
- Implement MySQL ORDER BY without using ASC or DESC?
- MySQL query to first set negative value in descending order and then positive value in ascending order
- How to arrange the fractions in ascending order and descending order?

Advertisements