
- 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
Get first date from timestamp in MySQL group by another column with duplicate value
For this, you can use aggregate function MIN() and GROUP BY. Let us first create a table −
mysql> create table DemoTable1870 ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, Value int, ShippingTimestamp varchar(100) ); Query OK, 0 rows affected (0.00 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1870(Value,ShippingTimestamp) values(10,'1570645800'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1870(Value,ShippingTimestamp) values(10,'1546194600'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1870(Value,ShippingTimestamp) values(11,'1573324200'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1870(Value,ShippingTimestamp) values(11,'1557599400'); Query OK, 1 row affected (0.00 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1870;
This will produce the following output −
+----+-------+-------------------+ | Id | Value | ShippingTimestamp | +----+-------+-------------------+ | 1 | 10 | 1570645800 | | 2 | 10 | 1546194600 | | 3 | 11 | 1573324200 | | 4 | 11 | 1557599400 | +----+-------+-------------------+ 4 rows in set (0.00 sec)
Here is the query to get first date from timestamp in MySQL &Minus;
mysql> select min(ShippingTimestamp) from DemoTable1870 group by Value;
This will produce the following output −
+------------------------+ | min(ShippingTimestamp) | +------------------------+ | 1546194600 | | 1557599400 | +------------------------+ 2 rows in set (0.00 sec)
- Related Articles
- Display only date from timestamp value in MySQL
- Implement MySQL conditional GROUP BY with NOT IN to filter records from duplicate column values
- Get timestamp date range with MySQL Select?
- Add records from corresponding duplicate values in another column with MySQL
- Group by one column and display corresponding records from another column with a separator in MySQL
- Get minimum value from a column (floating values) with corresponding duplicate ids in MySQL
- GROUP BY a column in another MySQL table
- MySQL query to select rows where column value is only 0, group by another column?
- Exclude rows based on column value when another duplicate column value is found in MySQL?
- Select minimum row value from a column with corresponding duplicate column values in MySQL
- MySQL group by for separate id without using GROUP BY to remove duplicate column row?
- Get only the date in timestamp in MySQL?
- Fetch the first letter of a column value and insert it in another column with MySQL
- Group MySQL rows in an array by column value?
- Get rows with GROUP BY in MySQL?

Advertisements