
Conditional (Case When) Statements in SQL
Last Updated on January 27, 2025 by Editorial Team
Author(s): Kamireddy Mahendra
Originally published on Towards AI.
A Must-Know Concept to Work in the Real World Projects
This member-only story is on us. Upgrade to access all of Medium.
In real-world projects, Itβs necessary to understand that the conditions will be numerous. So as per the conditions, we need to build a script to make anything work dynamically.
We can easily write and apply different conditions while we are writing any programming language, such as Python, Java, C++, etc.
Similarly, in SQL, we need to perform different operations based on various conditions. This might involve retrieving and updating data based on other columnβs data or even with the same columnβs data.
Either to update the current column or even if we want to extract any other columns as per the conditions of any other column data, we can do it with the help of these conditional statements easily.
Letβs consider Updating first.
Assume, I have an Employees table with different columns like Emp ID, Employee Name, Department, Age, city, and salary columns.
Now, I want to update(increments or hikes) the salaries of employees based on their departments. You can also consider any other columns as well.
It means we need to update single-column values with multiple conditions of different values of different columns or you can also consider the same column… Read the full blog for free on Medium.
Join thousands of data leaders on the AI newsletter. Join over 80,000 subscribers and keep up to date with the latest developments in AI. From research to projects and ideas. If you are building an AI startup, an AI-related product, or a service, we invite you to consider becoming aΒ sponsor.
Published via Towards AI