MySQL date equal - How to use equal to (=) to match date?
MySQL date equals operator returns the records from the table on the basis of date matched in the database. The equal to (=) operator is used to match the exact data in the database. In this tutorial we are going to match the date data type in the table with the help of equal to (=) operator. It returns all the matching records from the database. This query operator can also be used in combination with other sql operators.
We have also provided the video instruction of using equal to operator with the date date type. Here is the video:
Understand with Example
The Tutorial elaborate an example that helps you to understand MySQL date equal operator to match data in database. To understand it, we create a table 'Employees'. The create table statement is used to create a table employee with field name and data type respective.
Query:-
mysql> CREATE TABLE employees( Empid int(10), Empname varchar(60), date date ); |
Output:-
![]() |
Query:-
The insert into add the records or rows to the table 'Employee'.
mysql> insert into employees (Empid,Empname,date)values('01','Girish','2008-12-22'); mysql> insert into employees (Empid,Empname,date)values('02','Komal','2008-12-23'); |
Output:-
Query OK, 1 row affected (0.02 sec) Query OK, 1 row affected (0.02 sec) |
Query:-
The select show you the records from employees table.
mysql> select * from employees; |
Output:-
+-------+---------+------------+ | Empid | Empname | date | +-------+---------+------------+ | 1 | Girish | 2008-12-22 | | 2 | Komal | 2008-12-23 | +-------+---------+------------+ 2 rows in set (0.00 sec) |
Query:-
The below Query show you only those records from employee table as condition specified in where clause. In this Query this show you the records from a table 'Employee' based on the date '2008-12-22' condition in where clause.
Following example code matches the date using the equal to operator (=):
select * from employee where date like '2008-12-23';
Above query matches and returns all the records having date '2008-12-23'. You can also use the like operator but for date matching only equal to operator should be used. You should avoid using like operator with the date data type.
Example of Like Operator:
mysql> select * from employees where date = '2008-12-22'; |
Output:-
+-------+---------+------------+ | Empid | Empname | date | +-------+---------+------------+ | 1 | Girish | 2008-12-22 | +-------+---------+------------+ 1 row in set (0.00 sec) |
In this tutorial we have understood the use of like operator = to match date type data from database.
Related Tutorial: