The 365 Data Science team is proud to invite you to our own community forum. A very well built system to support your queries, questions and give the chance to show your knowledge and help others in their path of becoming Data Science specialists.
Anybody can ask a question
Anybody can answer
The best answers are voted up and moderated by our team

Use of Between And in SQL

Use of Between And in SQL


hire_date BETWEEN ‘2000-01-01’ AND ‘1990-01-01’
Result: NULL
hire_date BETWEEN ‘1990-01-01’ AND ‘2000-01-01’
Result: Hiring dates between the condition
In the 1st case, why the result is being shown as NULL whereas in the 2nd it shows the accurate results?

1 Answer

365 Team

Hi Neelanjan!
Thanks for reaching out.
It is normal to obtain non-null results only in the second case because numbers grow linearly from smaller to bigger when using BETWEEN-AND. That’s why with your first query, where you indicate the interval from a bigger to a smaller date value, you obtain an empty output, while with the second query, where the interval has been indicated from a smaller to a bigger date value, you obtain an output containing many rows of data.
Hope this helps.
The 365 Team

Thanks, it was surely helpful!!

2 weeks

Great! You are welcome!

1 week