Select all rows except from today in MySQL?


Let us first create a table −

mysql> create table DemoTable
   -> (
   -> Name varchar(100),
   -> DueDate datetime
   -> );
Query OK, 0 rows affected (0.54 sec)

Insert some records in the table using insert command. Let’s say the current date is “2019-07-03” −

mysql> insert into DemoTable values('Chris','2019-06-24');
Query OK, 1 row affected (0.12 sec)

mysql> insert into DemoTable values('Chris','2018-01-01');
Query OK, 1 row affected (0.13 sec)

mysql> insert into DemoTable values('Robert','2019-07-03');
Query OK, 1 row affected (0.21 sec)

mysql> insert into DemoTable values('Carol','2019-08-03');
Query OK, 1 row affected (0.22 sec)

Display all records from the table using select statement −

mysql> select *from DemoTable;

Output

This will produce the following output −

+--------+---------------------+
| Name   | DueDate             |
+--------+---------------------+
| Chris  | 2019-06-24 00:00:00 |
| Chris  | 2018-01-01 00:00:00 |
| Robert | 2019-07-03 00:00:00 |
| Carol  | 2019-08-03 00:00:00 |
+--------+---------------------+
4 rows in set (0.00 sec)

Here is the query to select all rows except those from today −

mysql> select *from DemoTable where date(DueDate) !=curdate();

Output

This will produce the following output −

+-------+---------------------+
| Name  | DueDate             |
+-------+---------------------+
| Chris | 2019-06-24 00:00:00 |
| Chris | 2018-01-01 00:00:00 |
| Carol | 2019-08-03 00:00:00 |
+-------+---------------------+
3 rows in set (0.00 sec)

Updated on: 30-Jun-2020

350 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements