From the course: MySQL Essential Training

Unlock this course with a free trial

Join today to access over 23,700 courses taught by industry experts.

Logical operators

Logical operators

- [Bill] Hi, I'm Bill Wyman. My SQL provides Boolean logical operators for combining logical values. Keep in mind that in SQL, zero is treated as false and any non-zero value is treated as true. So if I say select one and one, that's testing whether two true values are both true, and each of these ones could represent a logical expression that evaluates to true. So when I execute this, my result is one, because one is true. But if I say one and zero, then my result is false because both sides of the and operator are no longer true. Both sides of and must be true in order for it to return true. The OR operator requires that one side be true. So one OR zero is true, one OR one is also true, but zero OR zero is false because neither side of the OR operator is true. The XOR operator is exclusive OR, which means that one side and only one side must be true. So one XOR zero is true, but one XOR is not true. You can also use is and is not to compare two logical values. So in other words, I…

Contents