- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 distinct dates in MySQL from a column with date records
Let us first create a table −
mysql> create table DemoTable ( AdmissionDate datetime ); Query OK, 0 rows affected (8.99 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('2010-01-10 12:30:45'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('2010-01-10 12:30:45'); Query OK, 1 row affected (0.46 sec) mysql> insert into DemoTable values('2010-01-10 12:30:45'); Query OK, 1 row affected (0.71 sec) mysql> insert into DemoTable values('2010-01-12 12:30:45'); Query OK, 1 row affected (1.22 sec) mysql> insert into DemoTable values('2010-01-20 12:30:45'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values('2010-01-20 12:30:45'); Query OK, 1 row affected (0.51 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+---------------------+ | AdmissionDate | +---------------------+ | 2010-01-10 12:30:45 | | 2010-01-10 12:30:45 | | 2010-01-10 12:30:45 | | 2010-01-12 12:30:45 | | 2010-01-20 12:30:45 | | 2010-01-20 12:30:45 | +---------------------+ 6 rows in set (0.00 sec)
Following is the query to display distinct dates −
mysql> select distinct AdmissionDate from DemoTable;
This will produce the following output −
+---------------------+ | AdmissionDate | +---------------------+ | 2010-01-10 12:30:45 | | 2010-01-12 12:30:45 | | 2010-01-20 12:30:45 | +---------------------+ 3 rows in set (0.00 sec)
- Related Articles
- MySQL query to display the count of distinct records from a column with duplicate records
- Display month names and year from a column with date records with MySQL
- Filter dates from a table with DATE and NULL records in MySQL
- MySQL select distinct dates from datetime column in a table?
- Display records by grouping dates in MySQL
- Display record with today and tomorrow’s date from a column with date record in MySQL
- How to display the count from distinct records in the same row with MySQL?
- Select distinct values from three columns and display in a single column with MySQL
- How to compare the first date and the last date from a MySQL column with date records?
- Group by one column and display corresponding records from another column with a separator in MySQL
- Display distinct column name in MySQL
- Get Nth weekday of the month from a column with DATE records in MySQL
- Display records after a particular date in MySQL
- Select the date records between two dates in MySQL
- Display selected records from a MySQL table with IN() operator

Advertisements