
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
MySQL SELECT query to return records with specific month and year
For specific month, use MONTH() and for year, use YEAR() method. Let us first create a table −
mysql> create table DemoTable ( StudentName varchar(40), StudentAdmissionDate date ); Query OK, 0 rows affected (0.67 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('Chris','2019-01-21'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values('Robert','2018-09-05'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values('Mike','2019-09-05'); Query OK, 1 row affected (0.08 sec) mysql> insert into DemoTable values('David','2019-10-04'); Query OK, 1 row affected (0.14 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+-------------+----------------------+ | StudentName | StudentAdmissionDate | +-------------+----------------------+ | Chris | 2019-01-21 | | Robert | 2018-09-05 | | Mike | 2019-09-05 | | David | 2019-10-04 | +-------------+----------------------+ 4 rows in set (0.00 sec)
Following is the query to return records with specific month and year −
mysql> select *from DemoTable where month(StudentAdmissionDate)=09 and year(StudentAdmissionDate)=2019;
This will produce the following output −
+-------------+----------------------+ | StudentName | StudentAdmissionDate | +-------------+----------------------+ | Mike | 2019-09-05 | +-------------+----------------------+ 1 row in set (0.00 sec)
- Related Articles
- MySQL to fetch records based on a specific month and year?
- MySQL query to fetch date with year and month?
- How can fetch records from specific month and year in a MySQL table?
- How to compare Year, Month and Day in a MySQL query and display matching records
- MySQL query to select records beginning from a specific id
- MongoDB query to get specific month|year (not date)?
- Display month names and year from a column with date records with MySQL
- How to select month and year from dates in MySQL?
- MySQL query to select records with a particular date?
- MySQL query to select records with a particular date and time?
- MySQL query to return multiple row records with AND & OR operator
- MySQL query to count records that begin with specific letters
- MySQL query to select top 10 records?
- MySQL query to select bottom n records
- Filter the records of current day, month and year in MySQL?

Advertisements