DEV Community

Wilfred Odhiambo
Wilfred Odhiambo

Posted on

Understanding SQL: DDL, DML, Filtering, and CASE WHEN

Background

A few years ago when I was a student at a Kenyan university, I attempted to learn a computer programming language called GW-BASIC. I was thrilled at the beginning due to the logical nature of the language only for things to get ‘tough’ along the way perhaps due to lack of commitment from my side. Fast forward, in year 2026, I have developed an interest to learn a new skill to help me with data analysis and with that, I have the opportunity to study another computer language commonly referred to as SQL.

Introduction

Every time you search for something online, stream a movie, or check your bank balance, there is a database working behind the scenes. In most cases, that database understands one language: SQL. Think of a database as a giant, well organized filing cabinet, and SQL as the set of instructions you use to search through it, add new folders, or remove old ones.

SQL was invented in the 1970s by an IBM scientist and has been refined over the years so that it is used in banks, hospitals, schools, social media platforms, and e-commerce websites.

SQL stands for Structured Query Language. It is a computer language used to store, find, update, and delete information in a database. It is considered a declarative language in that you tell the computer what you want; for example, you say "Give me all sales above KES 10,000" and SQL figures out the rest. This is what has so far made it easy to learn compared to my earlier attempt to learn a computer language.

SQL encompasses data query language (DQL), data definition language (DDL), data control language (DCL), and data manipulation language (DML) covering everything from querying and inserting records to defining schemas and controlling access.

This article together with attached SQL script will demonstrate basic skills to deploy DQL, DDL and DML as a beginner.

What are DDL and DML

SQL commands are broadly grouped into two categories: DDL and DML. While they both operate on a database, they serve very different purposes as summarized below.

In simple terms, DDL shapes the container (the table), while DML manages what goes inside it. You must define the structure first before any data can be stored or retrieved.

CREATE, INSERT, UPDATE & DELETE in Practice

These are four core SQL commands to build and manage a simple database table.

CREATE — Define a new table

The CREATE command establishes the table structure, specifying column names and their data types.

INSERT — Add rows of data

Once the table exists, INSERT populates it with records.

UPDATE — Modify existing records

UPDATE changes values in existing rows. The WHERE clause is essential here — without it, every row would be updated.

DELETE — Remove specific rows

DELETE removes rows that match a condition. Again, WHERE determines which rows are affected.

Filtering with WHERE

The WHERE clause is one of the most powerful tools in SQL. It filters which rows a query acts on; whether you are selecting, updating, or deleting data. Without it, operations apply to every row in the table, often with unintended consequences.

SQL offers a rich set of operators to build flexible filters.

Practical examples illustrating these operators.

The LIKE operator is especially useful for partial text matching. The % symbol acts as a wildcard — 'A%' matches anything starting with "A", while '%son' matches anything ending in "son".

Transforming Data with CASE WHEN

CASE WHEN is SQL's version of an if-else statement.

It lets you create new labels or categories on the fly, directly within a query without changing any data in the table.

See below example used to convert numeric scores into descriptive performance labels.

This is incredibly useful for reporting and dashboards. Rather than storing a "performance" column in the database, you compute it dynamically based on the current scores. It keeps the data clean and the logic flexible.

Reflection

The most interesting part is realizing how much the WHERE clause changes the meaning of a query. The same DELETE or UPDATE statement becomes safe or catastrophic depending on whether you include it. The main challenge is dealing with syntax errors which slows down the learning process. In many occasions, I have had to rely on other AI tools to help me identify mistakes in the scripts which I believe is part of learning process.

Top comments (0)