SQL Comparison and IS NULL Operators: Data Filtering Basics
🚀 What Will You Learn in This Guide?
In this guide, Comparison Operators (=, >, <, <>, <=, >=) and
You will learn how to use the IS NULL statement.
These two structures allow you to limit data by conditions in your queries — for example:
Filters like “target > 40” or “result NULL”.
🧠 Technical Summary
Topic: Using Comparison and IS NULL operators in SQL WHERE statement
Purpose: To select data that meets certain conditions or to detect NULL values
Steps:
- Creating a MySQL database and table
- Filtering with comparison operators
- Querying NULL values
- Numerical and textual comparison examples
- IS NULL and operator combinations
⚙️ 1. Sample Database Setup
Connect to MySQL Server
mysql -u genixnode_kosucu -p
➡️ Allows you to log in to the MySQL terminal.
Create the Database
CREATE DATABASE kosu_vt;
USE kosu_vt;
➡️ Creates and activates a new “kosu_vt” database.
Create the Table
CREATE TABLE kosu_hedefleri (
isim VARCHAR(15),
hedef INT,
sonuc INT
);
➡️ Creates a table to store running goals and results.
Add Sample Data
INSERT INTO kosu_hedefleri VALUES
('Ayşe', 55, 48),
('Cem', 25, NULL),
('Mert', 45, 52),
('Elif', 40, NULL),
('Deniz', 30, 38),
('Serkan', 35, NULL),
('Lale', 40, 44);
➡️ Adds the goals and running results of seven people.
🔍 2. Using Comparison Operators
The WHERE clause evaluates the condition for each row. If the result returns true, the row is included in the query output.
Equality (=)
SELECT isim, hedef
FROM kosu_hedefleri
WHERE hedef = 40;
➡️ Returns records with target value 40.
Not Equal (<> veya !=)
SELECT isim, hedef
FROM kosu_hedefleri
WHERE hedef <> 40;
➡️ Returns records whose target is not 40.
Less than (<)
SELECT isim, hedef
FROM kosu_hedefleri
WHERE hedef < 40;
➡️ Lists people whose target is less than 40.
Greater than (>)
SELECT isim, hedef
FROM kosu_hedefleri
WHERE hedef > 40;
➡️ Selects targets greater than 40.
Greater than Equal (>=)
SELECT isim, hedef
FROM kosu_hedefleri
WHERE hedef >= 40;
➡️ Brings those whose target is 40 or more.
Alphabetical Comparison
SELECT isim
FROM kosu_hedefleri
WHERE isim < 'M';
➡️ Returns people whose names appear alphabetically before “M”.
⚙️ 3. IS NULL Operator: Querying for Missing Values
In SQL, NULL represents an unknown or missing value. Therefore, IS NULL is used instead of = for NULL checking.
Finding NULL Values
SELECT isim, sonuc
FROM kosu_hedefleri
WHERE sonuc IS NULL;
➡️ Lists people whose race results were not reported (NULL).
Finding Non-NULL Values
SELECT isim, sonuc
FROM kosu_hedefleri
WHERE sonuc IS NOT NULL;
➡️ Returns people whose results are available (NOT NULL).
🧩 4. Using Comparison and IS NULL
Example 1
SELECT isim
FROM kosu_hedefleri
WHERE hedef >= 40 OR sonuc IS NULL;
➡️ Selects those whose target is 40 or more or whose results are unknown.
Example 2
SELECT isim
FROM kosu_hedefleri
WHERE hedef <= 35 AND sonuc IS NOT NULL;
➡️ The target is 35 or less and the result returns the existing ones.
💬 Frequently Asked Questions (FAQ)
- Why NULL=NULL doesn't work?
NULL is not a value, it is an “unknown state”. Therefore IS NULL should be used.
- Do Comparison Operators also work in UPDATE/DELETE?
Yes. For example:
DELETE FROM kosu_hedefleri WHERE hedef < 20;
➡️ Deletes records whose target is less than 20.
- What is the Difference Between Text and Number Comparison?
Texts are evaluated in alphabetical order and numbers are evaluated according to mathematical size.
- Can it be used in Date Fields?
Yes, for example:
SELECT * FROM etkinlikler WHERE tarih > '2025-01-01';
➡️ Returns records after 2025.
- Does IS NULL Affect Performance?
On large tables it may slow down if there are no indexes, but on small datasets the difference is minimal.
🧭 Result
SQL's Comparison Operators and the IS NULL statement are the basic building blocks of data filtering. By using these tools correctly, you can optimize your queries and perform precise filtering on big data.
Create your SQL database on the GenixNode platform now to analyze your data on a powerful infrastructure.

