From the course: MySQL Essential Training (2019)

Comparison operators

- [Instructor] MySQL has a complete set of comparison operators which may be used with both numbers and strings, for example, if I type SELECT zero equals one and execute, you notice the result is zero. False results are represented by zero and true is represented by one. In SQL, zero is treated as false and any nonzero value is treated as true. So, if I say SELECT zero equals zero, now my result is one or true. If I say SELECT 0.0 equals zero, I get true and if I put the 0.0 in quote marks as a string, when a string is compared with the number, the string is first converted to its numeric equivalent, so that result is one which is true. If I say 0.1, I now get a zero for false or if I say 0.1 greater than zero, I get a one for true. If I say is it less than zero, that is false. And again, if I take the quote marks off, I get the same result. MySQL also supports other comparison operators, besides less than, greater than or equal, if I say nine is not equal to seven, I get true so that exclamation point followed by an equal sign is not equal to sometimes pronounced as bang equals. I can say less than or equals and that of course is false or I can say greater than or equals and that will be true. MySQL supports Boolean logical operators for combining conditions. I can say nine is greater than seven and put that in parentheses and 12 is less than 27 and when I execute this, I get true because nine is greater than seven and also 12 is less than 27, so when I combine those with a logical and, I have two truths on either side of the and operator and that result is true. I can say or instead of an and of course that will also be true because or is testing whether either of these conditions are true. MySQL supports is and is not for testing Boolean values. So, I can say nine is greater than seven is true. And I get true because it is true and if I test if it is not true, I get false because it is true. So, these are a few of the most common comparison operators. We'll see examples of these and other operators throughout this course.

Contents