Yes. You can use parenthesis to bind components of where clauses. This isn't necessary in your example, but if you had multiple and
and or
components, you might need parenthesis to either ensure correct order of operations or simply to self-document the query.
Example 1:
select *
from foo
where
(class='A' and subclass='B')
or (class='C' and subclass='D')
In example 1, the parens aren't strictly required because and
binds more tightly than or
, but if you had multiple or
conditions tied by and
you would need it to get correct results, as in example 2 below.
Example 2:
select *
from foo
where
(class='A' or class='B')
and (subclass='C' or subclass='D')
I use them in either case, because I don't like having to parse the sql in my head the same way the query optimizer does -- I'd rather be explicit about it and more quickly understand what the intent is.