'Mysql date range between given date date range

In my table structure mention below

Create tables using the GitHub-flavored markdown format

id course start_date end_date
1 course 1 2022-03-28 2022-03-28
2 course 2 2022-03-28 2022-03-30

while searching in my query I give input of date any course start date and end date between the below-given data range.

start_date end_date
2022-03-28 2022-03-28
2022-03-27 2022-03-28
2022-03-27 2022-03-30
2022-03-28 2022-03-30
2022-03-27 2022-03-31

The above all condition date given the result.



Solution 1:[1]

there are two formats to achieve your goals:

first one:

SELECT * FROM table WHERE date_column >= '2014-01-01' AND date_column <= '2015-01-01';

second one:

SELECT * FROM table WHERE date_column BETWEEN '2014-01-10' AND '2015-01-01';

you can choose any one one and just put the real table and columns

update based on comment

the provided is just an example and you can use both columns start_date and end_date as example:

SELECT * FROM table WHERE date_column_1 >= '2014-01-01' AND date_column_2 <= '2015-01-01';

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1