Below is my data and query,
academic year start date - 2018-01-01
academic year end date - 2018-06-30
Term table
term_id parent_id start_date end_date
1 null 2018-01-01 2018-01-30
2 1 2018-01-01 2018-01-10
3 1 2018-01-11 2018-01-20
4 null 2018-02-01 2018-02-28
5 4 2018-02-01 2018-02-10
6 4 2018-02-11 2018-02-20
I want to add new term which should not be in date range of term_id 1,2 and also in date range of academic year start and end date. But in my query it is not working below is my query,
I have entered, it should not entered from below query
start_date - 2018-02-11
end_date - 2018-02-25
SELECT * from term
where parent_id=null
and start_date >= 2018-02-11
and end_date <= 2018-02-25
and start_date >= 2018-01-01(academic year start date)
and end_date <= 2018-06-30(academic year end date)
Same for enter sub term it should be in parent term date range and unique in all sub term of same parent term. I have entered, which should not enter,
start_date - 2018-02-13
end_date -2018-02-18
My query is below,
SELECT * from term
where parent_id=4
and start_date >= 2018-02-13
and end_date <= 2018-02-18
and start_date >= 2018-02-01(parent term start date)
and end_date <= 2018-02-28(parent term end_date)
and start_date >= 2018-01-01(academic year start date)
and end_date <= 2018-06-30(academic year end date)