Big Data and Hadoop Training @$80 or Rs. 6,000 only - valid till Oct 17th Apply Now!

Mysql Date Search

Ads
 

Mysql Date Search

In this Tutorial you will learn how to' search Date in Mysql'. To understand this example, we create a table 'employee' with required fieldname and datatype respectively.

In this Tutorial you will learn how to' search Date in Mysql'. To understand this example, we create a table 'employee' with required fieldname and datatype respectively.

Mysql Date Search

     

In this Tutorial you will learn how to' search Date in Mysql'. To understand this example, we create a table 'employee' with required fieldname and datatype respectively. The Table employee has a 'empid' as Primary Key. The keyword create table employee is used to create a table 'employee'.

Create table "employee":

CREATE TABLE `employee` ( 
`id` bigint(20) NOT NULL auto_increment, 
`emp_name` varchar(100) NOT NULL, 
`emp_dob` date default NULL, 
PRIMARY KEY (`id`) 

Query to insert the record in the table "employee":

Now the Query insert into is used to add the records or  rows into table 'employee' 

insert into employee (emp_name,emp_dob)values('Sourabh','1985-11-07');
insert into employee (emp_name,emp_dob)values('Vineet','1983-11-07');
insert into employee (emp_name,emp_dob)values('Girish','1984-10-06');
insert into employee (emp_name,emp_dob)values('Sourabh','1982-01-05');

Query to retrieve the records from table "employee":

To view the details of the records from table 'employee' we run select query to retrieve it.

select * from employee;

Output:

mysql> select * from employee
+----+----------+------------
| id | emp_name | emp_dob
+----+----------+------------
| 1 | Sourabh | 1985-11-07
| 2 | Vineet | 1983-11-07
| 3 | Girish | 1984-10-06
| 4 | Sourabh | 1982-01-05
+----+----------+------------
4 rows in set (0.00 sec)

Query to Search record by Date:

The Query below returns the records details from table employee whose emp_dob is '1985-11-07'.

select * from employee where emp_dob='1985-11-07'

Output :

+----+----------+------------+
| id | emp_name | emp_dob |
+----+----------+------------+
| 1 | Sourabh | 1985-11-07 |
+----+----------+------------+

Ads

Ads