From the course: Quick Start Guide to SQL
Unlock this course with a free trial
Join today to access over 24,700 courses taught by industry experts.
Conditional expressions
From the course: Quick Start Guide to SQL
Conditional expressions
- [Instructor] Now let's learn about conditional functions. These are CASE and DECODE. They both act like IF-THEN-ELSE in SQL. Typically to use IF-THEN-ELSE, we need to write a procedure but by using these functions, we can avoid that. Here in case expression, we compare our expression with different comparison expressions and return the corresponding return expressions. This is the syntax for case. Let's look at an example. Now, based on an employee's designation, I want to increase their salary accordingly, so I give SELECT name, job, salary and I'm going to write this in multiple lines for better understanding. I start the CASE function. CASE, since I'm comparing the job, I give job WHEN, WHEN the job title is MANAGER, I want the salary to increase by 20%. WHEN the job is ANALYST, then I want the salary to increase by 15%. And WHEN his job title is CLERK, then I want it to increase by 10%. And WHEN the job…
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.