From the course: MySQL Essential Training
Unlock this course with a free trial
Join today to access over 24,200 courses taught by industry experts.
The CASE statement - MySQL Tutorial
From the course: MySQL Essential Training
The CASE statement
- [Instructor] Hi, I'm Bill Wyman. MySQL supports two forms of conditional expressions. The syntax is a little cumbersome, but here's how it works. For this lesson, I've copied some SQL from the chapter three exercise file, and we'll start by using the scratch database. Then I'm going to create a table called booltest. And this table has two columns, A and B, both of them integers, and we'll insert two values a one and a zero, and then we'll select, and I'll go ahead and execute all of this. And here's our result, our two columns, one row A is one and B is zero. There's two forms of the case syntax. We'll look at the first one here. The first form tests a Boolean condition. So here's the Boolean condition, and if it's true, then it gives the first result, which in this case is a string that says true. And if it's false, it gives the second result. And then there's end, and I'm giving this an alias of boolA for the first column and boolB for the second column with the two case…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.