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 answers ( 0 marked as helpful)
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.
Best,
The 365 Team
Best,
The 365 Team