- Read Tutorial
- Watch Guide Video
This section of the course covers control flow in MySql. If you've come from another programming language, the idea of control flow may already make sense to you. Control flow essentially is being able to say if one thing is true then I want these other things to happen.
Setting up an if-else type of conditionals, SQL has the ability to do that which is a very cool and very helpful type of feature. One thing that I use it for quite a bit is whenever I'm running a large query, and I have integer types inside of my database. So, say that I have a database of users and I want to be able to see which ones are active and which ones aren't.
But I don't want just to display a 0, 1, or 2, and in the database that's how they're stored. What I can do with case statements, which we're going to get into is I can actually have the SQL processed and say every single time you see a 0 for this column. I want you to say this user is active and every time that it is 1 they're not active. So you can perform all kinds of conditional logic and implement that in your application. That's what we're going to get into in this section.