
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 Matching Repeated Date Records Only Once in MySQL
Let’s say we are finding records matching with the current date. Since we want repeated matching records only once, use LIMIT.
For example, the current date is −
2019-10-02
Let us first create a table −
mysql> create table DemoTable1450 -> ( -> DueDate date -> ); Query OK, 0 rows affected (0.63 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1450 values('2019-09-30'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable1450 values('2019-10-02'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable1450 values('2019-10-02'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable1450 values('2019-10-02'); Query OK, 1 row affected (0.30 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1450;
This will produce the following output −
+------------+ | DueDate | +------------+ | 2019-09-30 | | 2019-10-02 | | 2019-10-02 | | 2019-10-02 | +------------+ 4 rows in set (0.00 sec)
Following is the query to display repeated matching date only once −
mysql> select * from DemoTable1450 where DueDate=curdate() limit 1;
This will produce the following output −
+------------+ | DueDate | +------------+ | 2019-10-02 | +------------+ 1 row in set (0.00 sec)
Advertisements