deepak deepak - 10 months ago 49
SQL Question

how to get data between dates

I have following table with data:

id startdate finishdate
4 2015-09-17 2016-09-28
5 2016-08-17 2016-09-12

Now i need data for this date -

For example if i enter this date
then only 1st data will display.

Now if i enter date -
then it will display both data.

i have tried with :

select * from customer where startdate >='2016-02-02' or finishdate<='2016-02-02'

but it is not working.

how can i achieve this ?

Answer Source

Your logic is simply backwards:

select c.*
from customer c
where startdate <= '2016-02-02' and finishdate >= '2016-02-02';

I advise you not to use between for dates. Here is a really good explanation by Aaron Bertrand on why that is a bad idea.