Display matching repeated date records only once in MySQL

MySQLMySQLi Database

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)
raja
Published on 10-Dec-2019 05:55:19
Advertisements