I am trying to use BETWEEN with column names instead of direct values, something like this:
SELECT * FROM table WHERE column1 BETWEEN column2 AND column3;
This returns something like 17 lines, but if I write:
SELECT * FROM table WHERE (column1 <= column2 AND column1 >= column3) OR (column1 >= column2 AND column1 <= column3)
I will go around 600 lines. In both cases, I only get rows where the column value is actually the average value, but the second method gives me much more results, so the 1st method has something wrong.
I suspect the problem may be using the BETWEEN clause with column names instead of pure values, and somehow SQL will convert the column names to actual values. Strange, but can someone enlighten me, please? Thanks
source
share