Search the MySQL manual:
Subscribe to the monthly
MySQL Newsletter!

6.3.1.1 Круглые скобки

( ... )

Круглые скобки используются для задания порядка вычислений в выражении. Например:

mysql> SELECT 1+2*3;
        -> 7
mysql> SELECT (1+2)*3;
        -> 9

User Comments

Posted by Phil Beynon on September 14 2003 6:08pm[Delete] [Edit]

The use of parentheses is also applicable to logic evaluation within select statements;

So;

select type from mytable where type = '2' AND pc1 = 'B38' OR type = '2' AND pc1 = 'B30' OR type = '2' AND pc1 = 'B31' OR type = '2' AND pc1 = 'B14' OR type = '2' AND pc1 = 'B47' OR type = '2' AND pc1 = 'B48' OR type = '2' AND pc1 = 'B45';

is exactly the same as, albeit shorter;

select type from mytable where type = '2' AND (pc1 = 'B38' OR pc1 = 'B30' OR pc1 = 'B31' OR pc1 = 'B14' OR pc1 = 'B47' OR pc1 = 'B48' OR pc1 = 'B45');

Where in the second example the parentheses force the OR functions to fully evaluate prior to the result being ANDed to the value selected from the 'type' field.

The table column name needs to be explicitly included for each instance of the OR though for correct evaluation of the select statement.
Hope this assists someone, I just spent 3 hours sussing it out!
Phil

Add your own comment.