SQL Parentheses and "AND" bug?

Francois Van Lerberghe fvanlerberghe at freegates.be
Tue Jul 8 08:09:33 CDT 2003


le 7-07-03 21:55, erobar at earthlink.net <erobar at earthlink.net> a écrit :

> Note: the ONLY difference is that I've added parentheses around the last 2
> criteria, which produces the right results.  With the first SQL statement, it
> returns items where table_B.field_B is 1 through 5!  So, the third criterion
> seems to be obliterated somehow....

I think it's a long standing problem.
And I think it's even better to group and enclose in parentheses all
conditions of the same table, not only the last
Thus I'd write this query as this :

select count(*) from table_A, table_B where
(table_A.field_A >= 3 and table_A.field_A <= 5) and
(table_B.field_B >= 3 and table_B.field_B <= 10)

Cheers

François Van Lerberghe
Thier Monty, 15A
B-4570 Marchin
Belgique



More information about the Valentina mailing list