Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL BETWEEN Operator conditional value in Reverse Order

Why the following SQL query show results?

     SELECT * FROM Products
     WHERE Price BETWEEN 10 AND 20;

but when we change the order of value it will not show any result?

     SELECT * FROM Products
     WHERE Price BETWEEN 20 AND 10;
like image 741
Abrar Ahmad Avatar asked Apr 23 '14 09:04

Abrar Ahmad


2 Answers

 SELECT * FROM Products
 WHERE Price BETWEEN 20 AND 10;

translates to

 SELECT * FROM Products
 WHERE Price >= 20 AND Price <= 10;
like image 109
Thorsten Kettner Avatar answered Sep 20 '22 16:09

Thorsten Kettner


BETWEEN returns TRUE if the value of test_expression is greater than or equal to the value of begin_expression and less than or equal to the value of end_expression. NOT BETWEEN returns TRUE if the value of test_expression is less than the value of begin_expression or greater than the value of end_expression.

In your case, your statement evaluates to greater than or equal to 20 AND less than or equal to 10

like image 34
Raj Avatar answered Sep 19 '22 16:09

Raj