Why this two expressions return different results? This is really stupid.
SELECT * FROM Table WHERE ID BETWEEN 3 AND 1
SELECT * FROM Table WHERE ID BETWEEN 1 AND 3
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
As the documentation says:
Doesn’t say anything about swapping the start_expression and end_expression to match min and max values. You should expect the result as documented, not as you believe it should.
For the curious out there, the ANSI SQL99 standard specifies that the BETWEEN predicate should include a clause for SYMMETRIC or ASYMMETRIC comparison. Only the SYMMETRIC one is allowed to swap the start_range and end_range, the ASYMMETRIC one is required to be strict. The ASYMMETRIC form is the implicit form. In other words an implementation that interprets
A BETWEEN X and Yas(A>=X AND A<=Y) OR (A>=Y AND A<=X), as the OP suggests, is not standard compliant.