I have a list of date ranges and I like to get a list of all months that are within these date ranges. I can query my date ranges like so:
Select id, start, end
From date_range
And this query would give the following output:
1, 01-01-2016, 25-03-2016
2, 26-03-2016, 30-03-2016
3, 30-12-2016, 08-01-2017
Now I would like to find a MySQL query that just lists all months within these date ranges. So it should give the following output:
01-2016
02-2016
03-2016
12-2016
01-2017
There are already examples here on how to get a list of month between two dates, such as:
- Creating a list of month names between two dates in MySQL
- How to get a list of months between two dates in mysql
But these examples are about a single date range, but I have multiple date ranges. It would be great if someone can find an sql query for my problem.