6
First of all, I understand that there is some logical motivation in the question. If something is between 1 and 3, in principle it is between 3 and 1.
What is not true if it is a trade that opens from 22h to 6h in the morning. Between 6h and 22h it will be closed. Between 22h and 6h will be open. In other words, concepts are often relativized.
That said, let’s answer the question:
It is so, because who defined the function wanted so. The interpretation of the creator(s) of the function is that the data will be in ascending order. It’s not about them having a better mind than you or the other way around. If you create a language and define that your BETWEEN will work independent of parameter order, I believe you will be right too.
Anyway, if you need to know independent order, just do this:
a BETWEEN( b, c ) OR a BETWEEN( c, b )
It may not be as elegant as calling a function only, but in return, knowing the "limitation" of the function, it may be useful at some point when the order is important.
Exaggerating: I could make a third language with a BETWEEN that gave inverted result if the parameters were reversed, it would be perfect in the case of the example I gave of working hours. 10 BETWEEN( 5, 15 ) => true
and 20 BETWEEN ( 15, 5 ) => true
(as if reversing the parameters, worth the "turn" outside the numbering, starting from 15 and going to the positive infinity, and from the negative infinity ending in 5)
In the end, what counts is documentation. And when it’s up to date ;)
because the between always picks up [higher] => [lower] as 15 > 10, it invalidates beetween. because there is no 15 to 10 interval.
– Ivan Ferrer
It’s okay that the command has as default pick the smaller - > larger. Now between 10 and 15 I have {10,11,12,13,14,15} and between 15 and 10 I have {15,14,13,12,11,10}.. the same interval however in another order... Thank you for the reply
– Enio Lacerda
Thanks for the answers. Doubt clarified after a mathematical understanding. Thank you
– Enio Lacerda
Enio, the problem is that it is so because it is so. I don’t know if you have a better answer than that. I could consider the opposite too, this would be up to a hand on the wheel in certain cases, but that’s not how it works in SQL.
– bfavaretto