- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- 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
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)
Advertisements