0

I am having difficulties finding what the actual difference between "conditionals" and "predicates" are in the context of SQL and Relational Database Management Systems. Do they mean the same thing?

For example, is a WHERE clause a conditional statement or a predicate? Or both?

2
  • 1
    It is neither of these things; it's a clause, as you have said yourself.
    – mustaccio
    Sep 8, 2020 at 11:58
  • To be more specific is a WHERE clause made up of conditionals or predicates? Sep 8, 2020 at 15:26

2 Answers 2

4

A predicate is something that has a boolean (true/false) value. A WHERE clause contains a predicate, simple or compound.

A conditional [statement or expression], such as if <predicate> then ... or case when <predicate> then ..., also necessarily contains a predicate. In its turn, a conditional expression itself can be a part of a predicate, as in this arguably contrived example:

...WHERE CASE WHEN DAYOFWEEK(NOW()) < 5 THEN 'weekday' ELSE 'weekend' END = some_column ...
2
  • 1
    This helps a lot and coincides with how I've been thinking about it. However, it still doesn't seem "complete". Maybe I am being too literal with the definitions but in SQL a "predicate" can resolve to True, False, or Unknown (NULL). Which doesn't fit the mathematical definition of a predicate being boolean. Am I just overthinking it? Sep 9, 2020 at 9:08
0

that is a good question.

Depending in the definitions, you can exclude them or not.

In my opion :

A WHERE Clause is conditional, because it decides at the end which rows are selected depending on the conditions.

For a predicate the result only can be True or False, and a WHERE clause can't return this result.

I thought about that you need predicates to decide if a row is in the result set or not, but the WHERE clause as total doesn't return True or False

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.