From the course: MySQL Essential Training (2019)

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

The IF function

The IF function

- [Instructor] MySQL supports a simple IF function. For this example, we'll use the scratch database. We're going to create a table called booltest with two columns, both integers named A and B. Insert a row with the values one and zero, and select from it, I'm going to go ahead and execute all of this with shift execute and you notice that the values are one and zero for our one row for A and B. Now let's take a look at the IF function. The IF function is fairly simple. I'll say select IF and inside the parenthesis there's three expressions. The first expression is a condition, so I'll say, A is less than five, and the second expression is the expression that's returned if the condition is true, and so I'll just put in a string that says true, and for the third expression, I'll put in false, that's the expression that's returned if the condition is not true, and I'll say from booltest, and I'll go ahead and execute that, and you see that the result is the string value of true because…

Contents