I have 2 dates to be filtered by 2 dates.
I have this data on my table
id date_from date_to name
1 2018-10-11 2018-10-25 LeBron James
2 2018-10-11 2018-10-25 Stephen Curry
3 2018-10-26 2018-11-10 Kevin Durant
What I wanted to do is to filter it base on the date range given. So If I have the 2 dates(2018-10-01 to 2018-10-22). I will only see id 1 and 2, and if I have (2018-10-12 to 2018-10-31) I will show all data.
My sample code I used start and end for the range
SELECT * FROM table WHERE (date_from BETWEEN @start AND @end) OR (date_to BETWEEN @start AND @end)
// The problem with this is that if no value found in range it will show me everything.
SELECT * FROM table WHERE (date_from >= @start AND date_from <= @end) AND (date_to >= @start AND date_to <= @end)
// The problem - No data will appear
What should I do, I am confused with lots of dates.