views:

190

answers:

2

Hi,

For example, if I did:

SELECT * FROM Users WHERE UserId BETWEEN 100 AND 1

what would the results be?

Edit: Sorry, you're right, I should have specified. I didn't want to know the exact number of rows that would return, I just wanted to know if it would return rows that were between 1 and 100 or if it would return rows from min(UserId) to 1 and 100 to max(UserId).

+1  A: 

This probably depends on your RDBMS, but why not just try it out? On MySQL, I get no rows from a BETWEEN 100 AND 1 query whereas I do get rows from asking for BETWEEN 1 and 100.

Paul A Jungwirth
+12  A: 
a BETWEEN b AND c

is shorthand for

b <= a and a <= c

So BETWEEN 100 and 1 won't match anything.

Andomar
when you say b <= a and a <= c, in this case b = 100 and c = 1, so wouldn't it return 100 <= a (or 100 to max(UserId)) and a <= 1 (or min(UserId) to 1)?
Matt
Matt: no, because intersection of these two sets is empty (AND operator). You would be correct if OR was used.
GSerg