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
User Comments
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.