Chapterبەش 9 · Lectureوانە 9.3

Better SELECT Queries: Conditions, Ranges, Lists, Patterns and NULLباشترکردنی فەرمانی SELECT: مەرجەکان، ماوەکان، لیست، شێوازی دەق و NULL

Ask a database real questions: compute columns and name them with AS, remove repeats with DISTINCT, filter rows with comparison operators, AND, OR and NOT, BETWEEN, IN and LIKE patterns, handle NULL correctly, and sort the answer with ORDER BY — all on one small shop database, in the MySQL that phpMyAdmin runs.

پرسیاری ڕاستەقینە لە بکە: نوێ بژمێرە و بە AS ناوی لێ بنێ، دووبارەکان بە DISTINCT لابە، بە ، AND، OR و NOT، BETWEEN، IN و شێوازەکانی LIKE بپاڵێوە، NULL بە دروستی بەکار بهێنە و وەڵامەکە بە ڕیز بکە — هەمووی لەسەر بچووکی دوکانێک، بەو MySQLـەی phpMyAdmin جێبەجێی دەکات.

34 min read34 خولەک خوێندنەوە · 24 stepsهەنگاو

What you will learnچی فێر دەبیت

  • Compute new columns in SELECT, name them with AS (backticks when the name has spaces) and remove repeated values with DISTINCT.
  • Filter rows with comparison operators on numbers, text and dates, and combine conditions with AND, OR, NOT and brackets.
  • Use BETWEEN (both ends included), IN and NOT IN instead of long chains of conditions.
  • Match text patterns with LIKE, % and _, and know when capital and small letters count as different in MySQL and SQLite.
  • Find missing values with IS NULL and IS NOT NULL, and explain why = NULL finds nothing.
  • Sort a result by several columns or by an alias, and know where NULL values appear.
  • نوێ لە SELECT بژمێریت، بە AS ناوی لێ بنێیت (ئەگەر ناوەکە بۆشایی تێدا بوو بە backtick) و نرخە دووبارەکان بە DISTINCT لابەریت.
  • بە لەسەر ژمارە، دەق و بەروار بپاڵێویت و بە AND، OR، NOT و کەوانە پێکەوە ببەستیت.
  • لە جیاتی زنجیرەیەکی درێژ لە ، BETWEEN (هەردوو سەر لەگەڵیدا)، IN و ⁦NOT IN⁩ بەکار بهێنیت.
  • دەق بە LIKE، % و _ لەگەڵ شێوازێک بەراورد بکەیت و بزانیت کەی پیتی گەورە و بچووک لە MySQL و SQLiteـدا جیاوازن.
  • نرخە ونبووەکان بە ⁦IS NULL⁩ و ⁦IS NOT NULL⁩ بدۆزیتەوە و ڕوونی بکەیتەوە بۆچی = NULL هیچ نادۆزێتەوە.
  • ئەنجامێک بەپێی چەند یان بەپێی ڕیز بکەیت و بزانیت نرخەکانی NULL لە کوێ دەردەکەون.

Asking the database better questionsپرسیاری باشتر لە بنکەدراوە

In Databases and SQL basics you met SELECT … FROM … WHERE, a first short list of operators (=, <>, AND, LIKE …) and ORDER BY. Real questions are richer, and each of those operators has rules worth knowing. Which phones cost less than 300,000 IQD and come from Samsung or Xiaomi? Which customers have no e-mail address? Which names start with S? This lesson gives SELECT the tools for such questions.

لە بنکەدراوەکان و بنەماکانی SQL فێری SELECT … FROM … WHERE، لیستێکی کورتی یەکەمی (=، <>، AND، LIKE …) و ORDER BY بوویت. پرسیاری ڕاستەقینە دەوڵەمەندترە و هەر یەک لەو یاسای خۆی هەیە کە دەبێت بیزانیت: کام مۆبایل لە ⁦300,000⁩ دینار هەرزانترە و هی Samsung یان Xiaomiـیە؟ کام کڕیار نییە؟ کام ناو بە S دەست پێدەکات؟ ئەم وانەیە ئامرازی وەڵامدانەوەی ئەم جۆرە پرسیارانە دەداتە SELECT.

A SELECT does two separate jobs. The list after SELECT chooses — and can compute — the columns of the answer. The chooses the rows: it tests a condition on every row and keeps only the rows where the condition is true.

دوو کاری جیاواز دەکات. ئەو لیستەی دوای SELECT دێت وەڵامەکە هەڵدەبژێرێت — و دەتوانێت بیانژمێرێت. هەڵدەبژێرێت: لەسەر هەموو تاقی دەکاتەوە و تەنها ئەو دەهێڵێتەوە کە تێدا ڕاستە.

The products table of the shop: twelve rows, with four of its seven columns shown (name, brand, category, price_iqd). On the left, the rows pass through a funnel labelled WHERE category = 'phone': the four phone rows go through, the other eight rows stay behind. On the right, the four rows reach a box labelled SELECT name, price_iqd, which keeps only two of the columns. The result is a small table of four rows and two columns.خشتەی productsـی دوکانەکە: دوازدە تۆمار، کە چوار لە حەوت ستوونەکەی پیشان دراون (name، brand، category، price_iqd). لە لای چەپ تۆمارەکان بە ناو قیفێکدا تێدەپەڕن کە ناوی WHERE category = 'phone'ـە: چوار تۆماری مۆبایلەکە تێدەپەڕن و هەشت تۆمارەکەی تر دەمێننەوە. لە لای ڕاست چوار تۆمارەکە دەگەنە سندووقێک بە ناوی SELECT name, price_iqd کە تەنها دوو ستوون دەهێڵێتەوە. ئەنجامەکە خشتەیەکی بچووکە بە چوار تۆمار و دوو ستوون.
WHERE keeps rows; the list after SELECT keeps (or computes) columns.WHERE دەهێڵێتەوە؛ لیستی دوای SELECT دەهێڵێتەوە (یان دەیانژمێرێت).CêIT

Type every example in the SQL tab of phpMyAdmin (Step 6: the SQL tab). All examples are written for — XAMPP actually runs , which behaves the same here. We checked every answer by running it in ; where SQLite or MariaDB gives a different answer, the lesson says so.

هەموو نموونەیەک لە تابی SQLـی phpMyAdmin بنووسە (هەنگاوی 6: تابی SQL). هەموو نموونەکان بۆ نووسراون — XAMPP لە ڕاستیدا کار پێ دەکات کە لێرەدا هەمان ڕەفتاری هەیە. هەموو وەڵامێکمان بە جێبەجێکردنی لە پشکنیوە؛ هەر شوێنێک SQLite یان MariaDB وەڵامێکی جیاواز بدات، وانەکە دەیڵێت.

Quick checkپشکنینی خێراWhich part of a SELECT decides which rows appear in the answer?کام بەشی بڕیار دەدات کام لە وەڵامەکەدا دەردەکەون؟

Our example: a phone and computer shopنموونەکەمان: دوکانێکی مۆبایل و کۆمپیوتەر

Both SQL lessons use one small database: a shop in Sulaimani that sells phones, laptops, chargers and headphones. It has three tables:

هەردوو وانەی SQL یەک بچووک بەکار دەهێنن: دوکانێک لە سلێمانی کە مۆبایل، ، و دەفرۆشێت. سێ هەیە:

  • products — 12 products with their brand, category, price in Iraqi dinars (price_iqd), how many are in stock and the day they were added.
  • customers — 6 customers in five cities of Kurdistan, with e-mail addresses at example.com.
  • sales — 20 sales in September and October 2026: which product, which customer, which seller (Rezan or Lana), the date, how many and how it was paid (cash, card or fib, a payment app).
  • products — ⁦12⁩ کاڵا لەگەڵ براند، جۆر، قیمەت بە دیناری عێراقی (price_iqd)، ژمارەی بەردەست لە کۆگا و ئەو ڕۆژەی زیاد کران.
  • customers — 6 کڕیار لە پێنج شاری کوردستان، لەگەڵ لە example.com.
  • sales — ⁦20⁩ فرۆشتن لە مانگەکانی ئەیلوول و تشرینی یەکەمی ⁦2026⁩: کام کاڵا، کام کڕیار، کام فرۆشیار (Rezan یان Lana)، بەروار، چەند دانە و چۆن پارەکەی دراوە (cash، card یان fib کە بەرنامەیەکی پارەدانە).

The names, prices and sales are invented. Three values are deliberately missing (NULL), because real data always has gaps: the stock of the ThinkPad has not been counted yet, the brand of the power bank is unknown and Soran gave no e-mail address.

ناو، قیمەت و فرۆشتنەکان دروستکراون. سێ نرخ بە ئەنقەست ون کراون (NULL)، چونکە ڕاستەقینە هەمیشە کەلێنی هەیە: ژمارەی ThinkPad لە کۆگا هێشتا نەژمێردراوە، براندی پاوەر بانکەکە نەزانراوە و Soran نەداوە.

Create the shop database: paste this into phpMyAdmin's SQL tabبنکەدراوەی دوکانەکە دروست بکە: ئەمە لە تابی SQLـی phpMyAdmin دابنێSQLRuns in the databaseلە ناو بنکەدراوە کار دەکات
-- A phone and computer shop in Sulaimani (invented data, prices in IQD)
CREATE TABLE products (
    product_id INT PRIMARY KEY,
    name       VARCHAR(60) NOT NULL,
    brand      VARCHAR(30),
    category   VARCHAR(30) NOT NULL,
    price_iqd  INT NOT NULL,
    stock      INT,
    added_on   DATE NOT NULL
);

CREATE TABLE customers (
    customer_id INT PRIMARY KEY,
    name        VARCHAR(40) NOT NULL,
    city        VARCHAR(30) NOT NULL,
    email       VARCHAR(80)
);

CREATE TABLE sales (
    sale_id     INT PRIMARY KEY,
    product_id  INT NOT NULL,
    customer_id INT NOT NULL,
    seller      VARCHAR(30) NOT NULL,
    sold_on     DATE NOT NULL,
    quantity    INT NOT NULL,
    payment     VARCHAR(10) NOT NULL,
    FOREIGN KEY (product_id) REFERENCES products (product_id),
    FOREIGN KEY (customer_id) REFERENCES customers (customer_id)
);

INSERT INTO products VALUES
    (1,  'Galaxy A15',          'Samsung', 'phone',      250000,    8, '2026-01-10'),
    (2,  'Redmi 13C',           'Xiaomi',  'phone',      165000,   12, '2026-02-03'),
    (3,  'Redmi Note 13',       'Xiaomi',  'phone',      285000,    6, '2026-03-15'),
    (4,  'iPhone 15',           'Apple',   'phone',     1350000,    2, '2026-04-20'),
    (5,  'IdeaPad Slim 3',      'Lenovo',  'laptop',     610000,    4, '2026-02-18'),
    (6,  'ThinkPad E14',        'Lenovo',  'laptop',     940000, NULL, '2026-08-30'),
    (7,  'VivoBook 15',         'Asus',    'laptop',     600000,    5, '2026-05-07'),
    (8,  'USB-C Charger 25W',   'Samsung', 'charger',     25000,   30, '2026-01-10'),
    (9,  'Fast Charger 33W',    'Xiaomi',  'charger',     18000,   25, '2026-03-15'),
    (10, 'Power Bank 20000mAh', NULL,      'charger',     30000,   15, '2026-06-01'),
    (11, 'Galaxy Buds FE',      'Samsung', 'headphones',  95000,    7, '2026-07-12'),
    (12, 'Wired Earphones',     'Xiaomi',  'headphones',   7500,   40, '2026-06-01');

INSERT INTO customers VALUES
    (1, 'Aram',   'Sulaimani', 'aram@example.com'),
    (2, 'Shilan', 'Erbil',     'shilan.k@example.com'),
    (3, 'Karwan', 'Duhok',     'karwan88@example.com'),
    (4, 'Dilan',  'Sulaimani', 'dilan@example.com'),
    (5, 'Hana',   'Halabja',   'hana.m@example.com'),
    (6, 'Soran',  'Kirkuk',    NULL);

INSERT INTO sales VALUES
    (1,  1,  1, 'Rezan', '2026-09-02', 1, 'cash'),
    (2,  8,  1, 'Rezan', '2026-09-02', 2, 'cash'),
    (3,  2,  3, 'Lana',  '2026-09-05', 1, 'fib'),
    (4,  11, 2, 'Lana',  '2026-09-07', 1, 'card'),
    (5,  9,  4, 'Rezan', '2026-09-10', 3, 'cash'),
    (6,  5,  5, 'Rezan', '2026-09-14', 1, 'fib'),
    (7,  3,  6, 'Lana',  '2026-09-18', 1, 'cash'),
    (8,  10, 3, 'Lana',  '2026-09-21', 2, 'fib'),
    (9,  1,  4, 'Rezan', '2026-09-26', 1, 'fib'),
    (10, 7,  2, 'Lana',  '2026-10-01', 1, 'card'),
    (11, 8,  5, 'Rezan', '2026-10-03', 1, 'cash'),
    (12, 2,  1, 'Rezan', '2026-10-05', 1, 'fib'),
    (13, 4,  6, 'Lana',  '2026-10-09', 1, 'cash'),
    (14, 9,  2, 'Rezan', '2026-10-12', 2, 'cash'),
    (15, 11, 3, 'Lana',  '2026-10-14', 1, 'fib'),
    (16, 3,  4, 'Rezan', '2026-10-17', 1, 'cash'),
    (17, 10, 1, 'Lana',  '2026-10-19', 1, 'fib'),
    (18, 1,  5, 'Rezan', '2026-10-21', 1, 'cash'),
    (19, 8,  3, 'Lana',  '2026-10-23', 3, 'fib'),
    (20, 2,  2, 'Rezan', '2026-10-24', 1, 'cash');
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 4-12

brand and stock may be empty: they have no NOT NULL. Money is a whole number of dinars, so INT is enough here (IQD has no fils in use); for prices with decimals use DECIMAL (MySQL data types).

brand و stock دەکرێت بەتاڵ بن: NOT NULLـیان نییە. پارەکە ژمارەیەکی تەواوی دینارە، بۆیە لێرە INT بەسە (دینار ئێستا فلسی بەکارهاتووی نییە)؛ بۆ قیمەتی کەرتی DECIMAL بەکار بهێنە (جۆرەکانی دراوەی SQL لە MySQL).

Lineدێڕی 21-31

Each sale points to a product and a customer with a .

هەر فرۆشتنێک بە ئاماژە بە کاڵایەک و کڕیارێک دەکات.

Lineدێڕی 33-45

One INSERT can add many rows, separated by commas (INSERT).

یەک INSERT دەتوانێت چەندین زیاد بکات کە بە فاریزە جیا کراونەتەوە (INSERT).

Our example: a phone and computer shopنموونەکەمان: دوکانێکی مۆبایل و کۆمپیوتەر

The products and the customersکاڵاکان و کڕیارەکان

Keep this screen in mind: almost every answer in the two lessons can be checked against these rows.

ئەم شاشەیە لە بیر بێت: نزیکەی هەموو وەڵامێکی ئەم دوو وانەیە دەتوانرێت بەم بپشکنرێت.

SQLRuns in the databaseلە ناو بنکەدراوە کار دەکات
SELECT * FROM products;
SQLRuns in the databaseلە ناو بنکەدراوە کار دەکات
SELECT * FROM customers;
Quick checkپشکنینی خێراWhich product has an unknown stock (NULL)?کام کاڵا ژمارەی کۆگاکەی نەزانراوە (NULL)؟

Our example: a phone and computer shopنموونەکەمان: دوکانێکی مۆبایل و کۆمپیوتەر

The salesفرۆشتنەکان

Each row of sales is one sale. product_id and customer_id say what was sold and to whom; you can look them up in the two tables on the previous screen. For example, sale 13 is the iPhone 15 (product 4) sold to Soran (customer 6) on 9 October.

هەر sales یەک فرۆشتنە. product_id و customer_id دەڵێن چی فرۆشراوە و بە کێ؛ دەتوانیت لە دوو شاشەی پێشوودا بیاندۆزیتەوە. بۆ نموونە، فرۆشتنی ⁦13⁩ بریتییە لە ⁦iPhone 15⁩ (کاڵای ⁦4⁩) کە لە 9ی تشرینی یەکەم بە Soran (کڕیاری ⁦6⁩) فرۆشراوە.

SQLRuns in the databaseلە ناو بنکەدراوە کار دەکات
SELECT * FROM sales;

Choosing and computing columnsهەڵبژاردن و ژماردنی ستوونەکان

After SELECT you list the columns you want. You can also write an : arithmetic with +, -, * and / on columns and numbers. The database works it out for every row of the answer. This is a computed column (a ): it appears only in the result — the table itself does not change.

دوای SELECT ئەو دەنووسیت کە دەتەوێن. دەتوانیت بنووسیت: ژماردن بە +، -، * و / لەسەر و ژمارەکان. بۆ هەموو وەڵامەکە دەیژمێرێت. ئەمە ە: تەنها لە ئەنجامەکەدا دەردەکەوێت — خودی ناگۆڕێت.

How much money is on the shelf for each laptop? Multiply the price by the stock:

بۆ هەر چەند پارە لەسەر ڕەفەکەیە؟ قیمەتەکە و ژمارەی کۆگا لێک بدە:

SQLRuns in the databaseلە ناو بنکەدراوە کار دەکات
SELECT name, price_iqd, stock, price_iqd * stock
FROM products
WHERE category = 'laptop';
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 1

The fourth column is computed. Its header is simply the expression.

چوارەم ژمێردراوە. سەردێڕەکەی خودی .

The ThinkPad's answer is NULL: its stock is unknown, so the total is unknown too. You will see why in Missing values: NULL.

وەڵامی ThinkPad NULLـە: ژمارەی کۆگاکەی نەزانراوە، بۆیە کۆکەشی نەزانراوە. لە نرخە ونبووەکان: NULL دەبینیت بۆچی.

Quick checkپشکنینی خێراAfter running SELECT name, price_iqd * stock FROM products;, what is stored in the table products?دوای جێبەجێکردنی SELECT name, price_iqd * stock FROM products;، چی لە products هەڵگیراوە؟

SQL Course for Beginners [Full Course]Programming with Mosh · Englishئینگلیزی · 15.5M viewsبینین · 304K likesلایک · Partبەشی 29:30–38:18 (ofلە 3:10:19)

Mosh's MySQL course chapters: computed columns with AS and DISTINCT, IS NULL, and sorting with ORDER BY and LIMIT.

چەند بەشێکی کۆرسی Mosh: بە AS و DISTINCT، IS NULL و بە و .

Plays 29:30-38:18 (The SELECT clause): arithmetic in SELECT, AS aliases and DISTINCT.

لە ⁦29:30⁩ تا ⁦38:18⁩ پەخش دەبێت (بەشی The SELECT clause): ژماردن لەناو SELECT، بە AS و DISTINCT.

Choosing and computing columnsهەڵبژاردن و ژماردنی ستوونەکان

Naming a column with ASناونانی ستوونێک بە AS

A header such as price_iqd * stock is hard to read, and PHP would have to use it as an array key. Give the column an with AS:

سەردێڕێکی وەک price_iqd * stock خوێندنەوەی قورسە و PHP دەبێت وەک بەکاری بهێنێت. بە AS بدە بە :

SQLRuns in the databaseلە ناو بنکەدراوە کار دەکات
SELECT name, price_iqd * stock AS stock_value
FROM products
WHERE category = 'laptop';

An alias with a space or a bracket needs quotes. In MySQL use backticks; single or double quotes also work in the SELECT list. Better still, avoid spaces and write stock_value.

کە بۆشایی یان کەوانەی تێدا بێت پێویستی بە کۆتەیشنە. لە MySQLـدا backtick بەکار بهێنە؛ کۆتەیشنی تاک یان جووتیش لە لیستی SELECTـدا کار دەکەن. باشتر وایە بۆشایی بەکار نەهێنیت و stock_value بنووسیت.

SQLRuns in the databaseلە ناو بنکەدراوە کار دەکات
SELECT name AS Product,
       price_iqd * stock AS `Stock value (IQD)`
FROM products
WHERE category = 'laptop';
Quoting an alias that contains spaces (Access: see SQL view)کۆتەیشنکردنی کە بۆشایی تێدایە (Access: بڕوانە ⁦SQL view⁩)
Whereلە کوێAn alias with spaces is written بۆشاییدار بەم شێوەیە دەنووسرێت
MySQL / MariaDBAS `Stock value`
Standard SQL, SQLite (MySQL accepts it too)SQLـی ستاندارد، ⁦SQLite (MySQL⁩ـیش وەری دەگرێت)AS "Stock value"
Microsoft AccessAS [Stock value]
Quick checkپشکنینی خێراWhich line correctly names the computed column Total price in MySQL?کام دێڕ لە MySQLـدا بە دروستی ناوی ⁦Total price⁩ لە دەنێت؟

Choosing and computing columnsهەڵبژاردن و ژماردنی ستوونەکان

DISTINCT: every value onceDISTINCT: هەر نرخێک یەک جار

SELECT brand FROM products; returns 12 rows, one per product, so Samsung appears three times and Xiaomi four times. DISTINCT removes the repeated rows from the answer:

SELECT brand FROM products; ⁦12⁩ دەگەڕێنێتەوە، یەکێک بۆ هەر کاڵایەک، بۆیە Samsung سێ جار و Xiaomi چوار جار دەردەکەون. DISTINCT لە وەڵامەکە لادەبات:

SQLRuns in the databaseلە ناو بنکەدراوە کار دەکات
SELECT DISTINCT brand FROM products;
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 1

Six different values. The unknown brand (NULL) is shown once as well.

شەش نرخی جیاواز. براندە نەزانراوەکە (NULL)یش یەک جار پیشان دەدرێت.

DISTINCT looks at the whole row of the answer. With two columns it keeps every different pair: Xiaomi appears three times below, because Xiaomi sells chargers, headphones and phones.

DISTINCT سەیری هەموو وەڵامەکە دەکات. لەگەڵ دوو هەموو جووتێکی جیاواز دەهێڵێتەوە: لە خوارەوە Xiaomi سێ جار دەردەکەوێت، چونکە Xiaomi ، و مۆبایل دەفرۆشێت.

SQLRuns in the databaseلە ناو بنکەدراوە کار دەکات
SELECT DISTINCT category, brand
FROM products
ORDER BY category, brand;
Quick checkپشکنینی خێراHow many rows does SELECT DISTINCT category FROM products; return?SELECT DISTINCT category FROM products; چەند دەگەڕێنێتەوە؟

Comparing values in WHEREبەراوردکردنی نرخەکان لە WHERE

A condition in WHERE usually compares a column with a value. SQL has six . Each test gives true or false for a row, and only the rows where it is true stay in the answer.

لە WHEREـدا زۆرجار لەگەڵ نرخێک بەراورد دەکات. SQL شەش هەیە. هەر تاقیکردنەوەیەک بۆ ڕاست یان هەڵە دەدات و تەنها ئەو تێیاندا ڕاستە لە وەڵامەکەدا دەمێننەوە.

The six comparison operators (row counts from our shop)شەش (ژمارەی لە دوکانەکەمانەوە)
OperatorMeaningواتاExample on the shopنموونە لەسەر دوکانەکەRows
=equal toیەکسانە بەbrand = 'Lenovo'2
<> or !=not equal to (both spellings work in MySQL)یەکسان نییە بە (هەردوو شێوەکە لە MySQL کار دەکەن)category <> 'phone'8
<less thanکەمترە لەprice_iqd < 300003
<=less than or equal toکەمترە یان یەکسانە بەstock <= 53
>greater thanزیاترە لەquantity > 15
>=greater than or equal toزیاترە یان یەکسانە بەadded_on >= '2026-06-01'4
SQLRuns in the databaseلە ناو بنکەدراوە کار دەکات
SELECT name, price_iqd FROM products WHERE price_iqd < 30000;

Write numbers without quotes. Put text and dates in straight single quotes. A date is written year first, '2026-06-01', so comparing dates works like comparing numbers: a later day is greater.

ژمارە بەبێ کۆتەیشن بنووسە. دەق و بەروار لە ناو کۆتەیشنی تاکی ڕاست (' ') دابنێ. بەروار بە ساڵ دەست پێدەکات، '2026-06-01'، بۆیە بەراوردکردنی بەروار وەک بەراوردکردنی ژمارە کار دەکات: ڕۆژێکی دواتر گەورەترە.

SQLRuns in the databaseلە ناو بنکەدراوە کار دەکات
SELECT name, added_on FROM products WHERE added_on >= '2026-06-01';

Text is compared letter by letter, like a dictionary. In MySQL's default capital and small letters count as the same, so brand = 'lenovo' finds the Lenovo rows. SQLite's = is : the same query there finds nothing (upper and lower case in SQLite).

دەق پیت بە پیت بەراورد دەکرێت، وەک فەرهەنگ. لە بنەڕەتیی MySQLـدا پیتی گەورە و بچووک وەک یەک هەژمار دەکرێن، بۆیە brand = 'lenovo' Lenovo دەدۆزێتەوە. =ـی SQLite : هەمان لەوێ هیچ نادۆزێتەوە (پیتی گەورە و بچووک لە SQLite).

SQLRuns in the databaseلە ناو بنکەدراوە کار دەکات
SELECT name, brand FROM products WHERE brand = 'lenovo';
Quick checkپشکنینی خێراWhich condition finds the sales from 1 October 2026 onwards?کام ئەو فرۆشتنانە دەدۆزێتەوە کە لە 1ی تشرینی یەکەمی ⁦2026⁩ بەدواوەن؟

Comparing values in WHEREبەراوردکردنی نرخەکان لە WHERE

= compares the whole value= هەموو نرخەکە بەراورد دەکات

= is true only when the whole value matches. Two phones are called Redmi …, but neither name is just Redmi, so this query finds nothing:

= تەنها کاتێک ڕاستە کە هەموو نرخەکە یەک بگرێتەوە. ناوی دوو مۆبایل بە Redmi … دەست پێدەکات، بەڵام هیچیان تەنها Redmi نییە، بۆیە ئەم هیچ نادۆزێتەوە:

SQLRuns in the databaseلە ناو بنکەدراوە کار دەکات
SELECT name FROM products WHERE name = 'Redmi';

To find values that only start with Redmi, use a pattern with LIKE (explained in Patterns with LIKE):

بۆ دۆزینەوەی ئەو نرخانەی تەنها بە Redmi دەست پێدەکەن، شێوازێک لەگەڵ LIKE بەکار بهێنە (لە شێواز بە LIKE ڕوون کراوەتەوە):

SQLRuns in the databaseلە ناو بنکەدراوە کار دەکات
SELECT name FROM products WHERE name LIKE 'Redmi%';
Quick checkپشکنینی خێراA customer's address is stored as 'Salim Street 12'. Which condition finds it?ناونیشانی کڕیارێک وەک 'Salim Street 12' هەڵگیراوە. کام دەیدۆزێتەوە؟

Combining conditions: AND, OR, NOTپێکەوەبەستنی مەرجەکان: AND، OR، NOT

Three join conditions: AND is true when both sides are true, OR when at least one side is true, and NOT turns true into false and false into true. They work as in every programming language (truth tables in and, or, not in Python; the same AND as a circuit in the AND gate). Attackers misuse the same OR: a typed ' OR '1'='1 makes the condition true for every row (SQL injection: the classic example).

سێ پێکەوە دەبەستن: AND کاتێک ڕاستە کە هەردوو لا ڕاست بن، OR کاتێک کە لانیکەم یەک لا ڕاست بێت و NOT ڕاست دەکاتە هەڵە و هەڵە دەکاتە ڕاست. وەک هەموو زمانێکی کار دەکەن ( لە and، or، not لە Python؛ هەمان AND وەک لە گەیتی AND). هەمان OR بە خراپی بەکار دەهێنن: نووسینی ' OR '1'='1 وا دەکات بۆ هەموو ڕیزێک ڕاست بێت (تێخزاندنی SQL: نموونە کلاسیکییەکە).

The shop owner asks: phones under 300,000 IQD from Samsung or Xiaomi. Here is a first try:

خاوەنی دوکانەکە دەپرسێت: مۆبایلی Samsung یان Xiaomi کە لە ⁦300,000⁩ دینار کەمتر بن. ئەمە یەکەم هەوڵە:

SQLRuns in the databaseلە ناو بنکەدراوە کار دەکات
SELECT name, brand, price_iqd
FROM products
WHERE category = 'phone' AND price_iqd < 300000
  AND brand = 'Samsung' OR brand = 'Xiaomi';
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 3-4

A charger and earphones are not phones! AND is done before OR, so this reads as (phone AND under 300,000 AND Samsung) OR Xiaomi — every Xiaomi product passes.

و مۆبایل نین! AND پێش OR جێبەجێ دەکرێت، بۆیە ئەمە وا دەخوێندرێتەوە: (مۆبایل AND کەمتر لە ⁦300,000 AND Samsung) OR Xiaomi⁩ — هەموو کاڵایەکی Xiaomi تێدەپەڕێت.

AND has a higher than OR, just as * comes before + in arithmetic. Brackets say what you mean:

بەپێی ، AND پێش OR جێبەجێ دەکرێت، هەروەک چۆن لە ژماردندا * پێش + دێت. کەوانە ئەوە دەڵێت کە مەبەستتە:

SQLRuns in the databaseلە ناو بنکەدراوە کار دەکات
SELECT name, brand, price_iqd
FROM products
WHERE category = 'phone' AND price_iqd < 300000
  AND (brand = 'Samsung' OR brand = 'Xiaomi');

NOT comes first of all three. NOT (A OR B) means neither A nor B: here, products that are not phones and do not cost less than 50,000 IQD.

NOT لە هەر سێکیان یەکەمە. NOT (A OR B) واتە نە A و نە B: لێرەدا ئەو کاڵایانەی مۆبایل نین و لە ⁦50,000⁩ دینار کەمتر نین.

SQLRuns in the databaseلە ناو بنکەدراوە کار دەکات
SELECT name, category
FROM products
WHERE NOT (category = 'phone' OR price_iqd < 50000);
Quick checkپشکنینی خێراHow many rows does this return? SELECT name FROM products WHERE category = 'charger' OR category = 'headphones' AND price_iqd > 50000;ئەمە چەند دەگەڕێنێتەوە؟ SELECT name FROM products WHERE category = 'charger' OR category = 'headphones' AND price_iqd > 50000;

Ranges with BETWEENماوە بە BETWEEN

BETWEEN low AND high is a short way to write >= low AND <= high. Both ends are included. Products from 250,000 to 600,000 IQD:

BETWEEN low AND high شێوەیەکی کورتە بۆ نووسینی >= low AND <= high. هەردوو سەرەکە لەگەڵیدان. کاڵاکانی نێوان ⁦250,000⁩ تا ⁦600,000⁩ دینار:

SQLRuns in the databaseلە ناو بنکەدراوە کار دەکات
SELECT name, price_iqd
FROM products
WHERE price_iqd BETWEEN 250000 AND 600000;
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 3

The Galaxy A15 costs exactly 250,000 and the VivoBook exactly 600,000: both ends are inside the range.

⁦Galaxy A15⁩ ڕێک ⁦250,000⁩ و VivoBook ڕێک ⁦600,000⁩ دینارە: هەردوو سەرەکە لە ناو .

Two pictures side by side. Left: a number line of prices from 0 to 700,000 IQD with the range BETWEEN 250000 AND 600000 drawn as a thick bar; both ends are filled dots, meaning they are included. Dots for the products sit on the line: Galaxy A15 at 250,000 and VivoBook 15 at 600,000 on the two ends, Redmi Note 13 at 285,000 inside, and IdeaPad Slim 3 at 610,000 and Redmi 13C at 165,000 just outside. Right: six brand boxes — Samsung, Xiaomi, Apple, Lenovo, Asus and a dashed box NULL for the unknown brand. IN ('Apple', 'Lenovo', 'Asus') picks exactly the three named boxes; the others are left out.دوو وێنە لە تەنیشت یەکتر. چەپ: هێڵێکی ژمارەیی بۆ قیمەت لە 0 تا 700,000 دینار کە ماوەی BETWEEN 250000 AND 600000 وەک شریتێکی ئەستوور لەسەری کێشراوە؛ هەردوو سەرەکە خاڵی پڕن، واتە لەگەڵیدان. خاڵی کاڵاکان لەسەر هێڵەکەن: Galaxy A15 لە 250,000 و VivoBook 15 لە 600,000 لەسەر دوو سەرەکە، Redmi Note 13 لە 285,000 لە ناوەوە و IdeaPad Slim 3 لە 610,000 و Redmi 13C لە 165,000 هەر لە دەرەوە. ڕاست: شەش سندووقی براند — Samsung، Xiaomi، Apple، Lenovo، Asus و سندووقێکی هێڵ‌پچڕپچڕی NULL بۆ براندی نەزانراو. IN ('Apple', 'Lenovo', 'Asus') ڕێک ئەو سێ سندووقە ناوبراوە هەڵدەبژێرێت؛ ئەوانی تر دەمێننەوە.
BETWEEN keeps a range with both ends included; IN keeps the values named in a list.BETWEEN دەهێڵێتەوە کە هەردوو سەرەکەی لەگەڵدایە؛ IN ئەو نرخانە دەهێڵێتەوە کە لە لیستێکدا ناو براون.CêIT

NOT BETWEEN keeps everything outside the range — here the very cheap and the very expensive products:

NOT BETWEEN هەموو ئەوەی لە دەرەوەی دەهێڵێتەوە — لێرەدا کاڵا زۆر هەرزان و زۆر گرانەکان:

SQLRuns in the databaseلە ناو بنکەدراوە کار دەکات
SELECT name, price_iqd
FROM products
WHERE price_iqd NOT BETWEEN 20000 AND 1000000;

BETWEEN works on dates too. The sales of the first nine days of October:

BETWEEN لەسەر بەرواریش کار دەکات. فرۆشتنەکانی نۆ ڕۆژی یەکەمی تشرینی یەکەم:

SQLRuns in the databaseلە ناو بنکەدراوە کار دەکات
SELECT sale_id, sold_on, payment
FROM sales
WHERE sold_on BETWEEN '2026-10-01' AND '2026-10-09';
Quick checkپشکنینی خێراHow many sales does WHERE sold_on BETWEEN '2026-09-01' AND '2026-09-30' keep?WHERE sold_on BETWEEN '2026-09-01' AND '2026-09-30' چەند فرۆشتن دەهێڵێتەوە؟

Lists with IN and NOT INلیست بە IN و ⁦NOT IN⁩

IN (…) is true when the value is one of the values in the list. It is a short form of several ORs on the same column:

IN (…) کاتێک ڕاستە کە نرخەکە یەکێک بێت لە نرخەکانی ناو لیستەکە. شێوەیەکی کورتە بۆ چەند ORـێک لەسەر هەمان :

SQLRuns in the databaseلە ناو بنکەدراوە کار دەکات
SELECT name, brand FROM products
WHERE brand = 'Apple' OR brand = 'Lenovo' OR brand = 'Asus';

SELECT name, brand FROM products
WHERE brand IN ('Apple', 'Lenovo', 'Asus');
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 1-5

Both queries give the same four rows; the second is shorter and easier to change.

هەردوو هەمان چوار دەدەن؛ دووەمیان کورتترە و گۆڕینی ئاسانترە.

NOT IN keeps the values that are not in the list. Brands other than Samsung and Xiaomi:

NOT IN ئەو نرخانە دەهێڵێتەوە کە لە لیستەکەدا نین. براندەکانی جگە لە Samsung و Xiaomi:

SQLRuns in the databaseلە ناو بنکەدراوە کار دەکات
SELECT name, brand FROM products
WHERE brand NOT IN ('Samsung', 'Xiaomi');
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 2

The power bank is missing! Its brand is NULL, and SQL cannot say whether an unknown brand is in the list or not, so the row is not kept.

پاوەر بانکەکە ون بووە! براندەکەی NULLـە و SQL ناتوانێت بڵێت براندێکی نەزانراو لە لیستەکەدایە یان نا، بۆیە ناهێڵرێتەوە.

If the power bank belongs in the answer, ask for the NULL rows yourself:

ئەگەر پاوەر بانکەکە دەبێت لە وەڵامەکەدا بێت، خۆت داوای NULL بکە:

SQLRuns in the databaseلە ناو بنکەدراوە کار دەکات
SELECT name, brand FROM products
WHERE brand NOT IN ('Samsung', 'Xiaomi') OR brand IS NULL;
Quick checkپشکنینی خێراWhich condition is the same as payment IN ('cash', 'card')?کام وەک payment IN ('cash', 'card')ـە؟

Patterns with LIKEشێواز بە LIKE

LIKE compares text with a pattern. A pattern is ordinary text with two in it:

LIKE دەق لەگەڵ شێوازێک بەراورد دەکات. شێواز دەقێکی ئاساییە کە دوو تێدایە:

  • % stands for any number of characters — many, one or none.
  • _ (underscore) stands for exactly one character.
  • % جێی هەر ژمارەیەک دەگرێتەوە — زۆر، یەک یان هیچ.
  • _ (هێڵی ژێرەوە) جێی ڕێک یەک دەگرێتەوە.
Patterns tried on the products (first three) and the customers (last two)شێوازەکان لەسەر کاڵاکان (سێ یەکەم) و کڕیارەکان (دوو کۆتایی) تاقی کراونەتەوە
PatternشێوازMeansواتاQuery on the shop لەسەر دوکانەکەAnswerوەڵام
'Galaxy%'starts with Galaxyبە Galaxy دەست پێدەکاتname LIKE 'Galaxy%'Galaxy A15, Galaxy Buds FE
'%13'ends with 13بە ⁦13⁩ کۆتایی دێتname LIKE '%13'Redmi Note 13
'%charger%'contains charger anywherechargerـی لە هەر شوێنێکدا تێدایەname LIKE '%charger%'USB-C Charger 25W, Fast Charger 33W
'_a%'the second letter is aپیتی دووەم aـیەname LIKE '_a%'Karwan, Hana
'____'exactly four charactersڕێک چوار name LIKE '____'Aram, Hana
SQLRuns in the databaseلە ناو بنکەدراوە کار دەکات
SELECT name FROM products WHERE name LIKE '%charger%';
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 1

The names say Charger with a capital C, the pattern a small c — LIKE still matches (see capital or small letters).

ناوەکان Charger بە Cـی گەورە دەڵێن و شێوازەکە بە cـی بچووک — LIKE هێشتا یەکیان دەگرێتەوە (بڕوانە پیتی گەورە یان بچووک).

Quick checkپشکنینی خێراWhich customers does name LIKE '%an' find?name LIKE '%an' کام کڕیار دەدۆزێتەوە؟

Patterns with LIKEشێواز بە LIKE

Worked example: begins with S, ends with N, at least three lettersنموونەی شیکراوە: بە S دەست پێدەکات، بە N کۆتایی دێت، لانیکەم سێ پیت

Which customers have a name that begins with S, ends with N and has at least three letters? Build the pattern piece by piece:

کام کڕیار ناوێکی هەیە کە بە S دەست پێدەکات، بە N کۆتایی دێت و لانیکەم سێ پیتە؟ شێوازەکە پارچە پارچە دروست بکە:

  1. S — the first letter is S.

    S — پیتی یەکەم Sـە.

  2. _ — then exactly one letter. This makes the name at least three letters long (S + one letter + N).

    _ — پاشان ڕێک یەک پیت. ئەمە وا دەکات ناوەکە لانیکەم سێ پیت بێت (⁦S +⁩ یەک پیت + N).

  3. % — then any number of letters, also none.

    % — پاشان هەر ژمارەیەک پیت، تەنانەت هیچ.

  4. N — the last letter is N.

    N — دوایین پیت Nـە.

SQLRuns in the databaseلە ناو بنکەدراوە کار دەکات
SELECT name FROM customers WHERE name LIKE 'S_%N';
Animation. The pattern S_%N is checked against six customer names one by one. Aram: no, the first letter is A. Shilan: yes — S, then h for the underscore, ila for the percent sign, and the last letter n matches N because letter case is ignored. Karwan: no, it ends with n but begins with K. Soran: yes. Hana: no, it neither begins with S nor ends with N. Dilan: no, it begins with D. The last frame shows the answer: Shilan and Soran.
Animation. The pattern S_%N is checked against six customer names one by one. Aram: no, the first letter is A. Shilan: yes — S, then h for the underscore, ila for the percent sign, and the last letter n matches N because letter case is ignored. Karwan: no, it ends with n but begins with K. Soran: yes. Hana: no, it neither begins with S nor ends with N. Dilan: no, it begins with D. The last frame shows the answer: Shilan and Soran.
LIKE 'S_%N' tried on six names, one at a time.⁦LIKE 'S_%N⁩' یەک یەک لەسەر شەش ناو تاقی دەکرێتەوە.CêIT

Why the _? Without it, 'S%N' would also accept a two-letter name such as Sn, because % may be empty. With it, at least one letter must stand between S and N:

بۆچی _؟ بەبێ ئەو، 'S%N' ناوێکی دوو پیتی وەک Snیش وەردەگرێت، چونکە % دەکرێت بەتاڵ بێت. لەگەڵ ئەودا دەبێت لانیکەم یەک پیت لە نێوان S و N دابێت:

SQLRuns in the databaseلە ناو بنکەدراوە کار دەکات
SELECT 'Sn' LIKE 'S%N', 'Sn' LIKE 'S_%N', 'Shilan' LIKE 'S_%N';
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 1

LIKE gives 1 for a match and 0 for no match.

LIKE بۆ یەکگرتنەوە 1 و بۆ یەکنەگرتنەوە 0 دەدات.

Patterns with LIKEشێواز بە LIKE

Capital or small letters?پیتی گەورە یان بچووک؟

In the worked example, Shilan ends with a small n but the pattern says N — and it still matches. LIKE follows the column's . MySQL's default collations (utf8mb4_0900_ai_ci in MySQL 8.4, utf8mb4_general_ci in phpMyAdmin on XAMPP) end in _ci, case-insensitive: capital and small letters count as the same.

لە نموونە شیکراوەکەدا، Shilan بە nـی بچووک کۆتایی دێت بەڵام شێوازەکە N دەڵێت — و هێشتا یەک دەگرێتەوە. LIKE بەدوای دەڕوات. بنەڕەتییەکانی MySQL (utf8mb4_0900_ai_ci لە ⁦MySQL 8.4⁩، utf8mb4_general_ci لە phpMyAdmin لەسەر XAMPP) بە _ci کۆتایی دێن، واتە ⁦case-insensitive⁩: پیتی گەورە و بچووک وەک یەک هەژمار دەکرێن.

Letter case in MySQL and SQLite (SQLite column run in SQLite 3.51; MySQL column from the MySQL 8.4 manual)گەورە و بچووکیی پیت لە MySQL و SQLite (ستوونی SQLite لە ⁦SQLite 3.51⁩ جێبەجێ کراوە؛ ستوونی MySQL لە ڕێبەری ⁦MySQL 8.4⁩ـەوە)
TestتاقیکردنەوەMySQL (default collation)MySQL ( بنەڕەتی)SQLite
'Shilan' = 'shilan'1 — equal1 — یەکسانن0 — = is case-sensitive0 — =
'Shilan' LIKE 'shilan'11 — LIKE ignores case for A–Z⁦1 — LIKE⁩ گەورە و بچووکیی A تا Z پشتگوێ دەخات
'Shilan' LIKE 'shilan' COLLATE utf8mb4_bin0 — a binary collation compares the exact bytes0 — binary وەک خۆیان بەراورد دەکات1 — SQLite's LIKE ignores the COLLATE; its GLOB 'S*' is case-sensitive⁦1 — LIKE⁩ـی SQLite بڕگەی COLLATE پشتگوێ دەخات؛ GLOB 'S*'ـەکەی
'شیلان' LIKE 'ش%'11
  • To make a MySQL comparison case-sensitive, add a binary collation: name LIKE 'S%' COLLATE utf8mb4_bin. (The shorter name LIKE BINARY 'S%' also works, but the BINARY operator is deprecated in MySQL 8.4.)
  • SQLite's LIKE ignores case only for the English letters A–Z; its = never ignores case (SQLite and letter case).
  • Kurdish letters have no capital and small forms, so for Kurdish text the question does not arise.
  • بۆ ئەوەی بەراوردێکی MySQL بێت، binary زیاد بکە: name LIKE 'S%' COLLATE utf8mb4_bin. (شێوە کورتەکەی name LIKE BINARY 'S%'ـیش کار دەکات، بەڵام BINARY لە ⁦MySQL 8.4⁩ـدا .)
  • LIKEـی SQLite تەنها بۆ پیتە ئینگلیزییەکانی A تا Z گەورە و بچووکیی پیت پشتگوێ دەخات؛ =ـەکەی هەرگیز پشتگوێی ناخات (SQLite و گەورە و بچووکیی پیت).
  • پیتە کوردییەکان شێوەی گەورە و بچووکیان نییە، بۆیە بۆ دەقی کوردی ئەم پرسیارە دروست نابێت.
Quick checkپشکنینی خێراIn phpMyAdmin (default collation), does WHERE name LIKE 'shilan' find the customer Shilan?لە phpMyAdmin ( بنەڕەتی)، ئایا WHERE name LIKE 'shilan' کڕیاری Shilan دەدۆزێتەوە؟

Patterns with LIKEشێواز بە LIKE

NOT LIKE, a real % sign, and Access⁦NOT LIKE⁩، نیشانەی %ـی ڕاستەقینە و Access

NOT LIKE keeps the values that do not match. The phones that are not Redmi phones:

NOT LIKE ئەو نرخانە دەهێڵێتەوە کە یەک ناگرنەوە. ئەو مۆبایلانەی Redmi نین:

SQLRuns in the databaseلە ناو بنکەدراوە کار دەکات
SELECT name FROM products
WHERE category = 'phone' AND name NOT LIKE 'Redmi%';

To search for a real % or _, choose an escape character with ESCAPE; the character after it is taken literally. MySQL also treats a backslash as the escape character by default ('%10\%'), but SQLite does not, so ESCAPE is the portable way:

بۆ گەڕان بەدوای % یان _ـی ڕاستەقینە، بە ESCAPE هەڵبژێرە؛ ئەو دوای ئەو دێت وەک خۆی وەردەگیرێت. MySQL بە شێوەی بنەڕەتی backslashـیش بەم کارە دادەنێت ('%10\%')، بەڵام SQLite نا، بۆیە ESCAPE ڕێگەیەکە لە هەردووکیاندا کار دەکات:

SQLRuns in the databaseلە ناو بنکەدراوە کار دەکات
SELECT 'Save 10%' LIKE '%10!%' ESCAPE '!',
       'Save 100' LIKE '%10!%' ESCAPE '!';
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 1-2

!% means a real percent sign. The first text ends with 10%, the second with 100.

!% واتە نیشانەیەکی سەدیی ڕاستەقینە. دەقی یەکەم بە ⁦10%⁩ کۆتایی دێت، دووەمیان بە ⁦100⁩.

Quick checkپشکنینی خێراWhich pattern finds the e-mail addresses that contain a dot before the @?کام شێواز دەدۆزێتەوە کە خاڵێکیان پێش @ تێدایە؟

Missing values: NULLنرخە ونبووەکان: NULL

NULL means unknown or missing. It is not 0 and it is not an empty text '': the stock of the ThinkPad is not zero, it has simply not been counted yet.

NULL واتە نەزانراو یان ون. 0 نییە و دەقی بەتاڵی ''ـیش نییە: ژمارەی کۆگای ThinkPad سفر نییە، تەنها هێشتا نەژمێردراوە.

Definitionپێناسە

A special value meaning "no value". PHP writes it null (or NULL), Java and C# null, Python None; a function that returns nothing gives this value.

نرخێکی تایبەتە بە واتای «هیچ نرخ». PHP بە null (یان NULL) دەینووسێت، Java و ⁦C#⁩ بە null و Python بە None؛ کە هیچ ناگەڕێنێتەوە ئەم نرخە دەدات.

In SQL, NULL is the mark for a missing value in any column, whatever its type.

لە SQLـدا NULL نیشانەی نرخێکی ونە لە هەر ، جۆرەکەی هەرچییەک بێت.

A first attempt to find it fails:

یەکەم هەوڵ بۆ دۆزینەوەی ئەم کاڵایە سەرکەوتوو نابێت:

SQLRuns in the databaseلە ناو بنکەدراوە کار دەکات
SELECT name, stock FROM products WHERE stock = NULL;

Nothing is ever equal to an unknown value — not even another NULL. Any comparison with NULL gives NULL (unknown), and WHERE keeps only the rows where the condition is true. Use IS NULL and IS NOT NULL:

هیچ شتێک هەرگیز یەکسان نییە بە نرخێکی نەزانراو — تەنانەت NULLـێکی تریش. ئەنجامی هەر بەراوردێک لەگەڵ NULL دەبێتە NULL (نەزانراو) و WHERE تەنها ئەو دەهێڵێتەوە کە تێیاندا ڕاستە. IS NULL و IS NOT NULL بەکار بهێنە:

SQLRuns in the databaseلە ناو بنکەدراوە کار دەکات
SELECT name, stock FROM products WHERE stock IS NULL;
SQLRuns in the databaseلە ناو بنکەدراوە کار دەکات
SELECT NULL = NULL, 5 + NULL, NULL IS NULL, 0 IS NULL, '' IS NULL;
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 1

NULL = NULL and 5 + NULL are unknown. Only IS NULL gives a clear answer: 1 for NULL, 0 for zero and for the empty text.

NULL = NULL و 5 + NULL نەزانراون. تەنها IS NULL وەڵامێکی ڕوون دەدات: 1 بۆ NULL، 0 بۆ سفر و بۆ دەقی بەتاڵ.

Quick checkپشکنینی خێراWhich query lists the customers who gave no e-mail address?کام ئەو کڕیارانە پیشان دەدات کە نەداوە؟

SQL Course for Beginners [Full Course]Programming with Mosh · Englishئینگلیزی · 15.5M viewsبینین · 304K likesلایک · Partبەشی 1:11:51–1:14:18 (ofلە 3:10:19)

Mosh's MySQL course chapters: computed columns with AS and DISTINCT, IS NULL, and sorting with ORDER BY and LIMIT.

چەند بەشێکی کۆرسی Mosh: بە AS و DISTINCT، IS NULL و بە و .

Plays 1:11:51-1:14:18 (The IS NULL operator): finding missing values with IS NULL and IS NOT NULL.

لە ⁦1:11:51⁩ تا ⁦1:14:18⁩ پەخش دەبێت (بەشی The IS NULL operator): دۆزینەوەی بە IS NULL و IS NOT NULL.

Missing values: NULLنرخە ونبووەکان: NULL

NULL in calculations, and COALESCENULL لە ژماردندا و COALESCE

  • Arithmetic with NULL gives NULL. That is why the ThinkPad's price_iqd * stock was NULL in Choosing and computing columns.
  • <> skips NULL too. WHERE brand <> 'Samsung' returns 8 rows, not 9: the power bank's unknown brand might be Samsung, so SQL does not keep it.
  • COALESCE(a, b) gives the first value that is not NULL — useful for showing a default in the answer:
  • هەر ژماردنێک NULLـی تێدا بێت، ئەنجامەکەی NULLـە. لەبەر ئەوە price_iqd * stockـی ThinkPad لە هەڵبژاردن و ژماردنی ستوونەکان NULL بوو.
  • <>ـیش NULL پشتگوێ دەخات. WHERE brand <> 'Samsung' 8 دەگەڕێنێتەوە، نەک 9: لەوانەیە براندە نەزانراوەکەی پاوەر بانکەکە Samsung بێت، بۆیە SQL نایهێڵێتەوە.
  • COALESCE(a, b) یەکەم نرخ دەدات کە NULL نەبێت — بۆ پیشاندانی لە وەڵامدا بەسوودە:
SQLRuns in the databaseلە ناو بنکەدراوە کار دەکات
SELECT name,
       COALESCE(stock, 0) AS stock_or_zero,
       COALESCE(brand, 'no brand') AS brand
FROM products
WHERE stock IS NULL OR brand IS NULL;
Everyday analogyنموونەیەک لە ژیانی ڕۆژانەوە

Think of a school form. A pupil who writes 0 in the box How many brothers? has answered; a pupil who leaves the box empty has not. NULL is the empty box: you cannot say it equals 0, nor that it equals another empty box.

فۆرمێکی قوتابخانە بهێنە پێش چاو. قوتابییەک کە لە خانەی چەند براتان هەیە؟ دەنووسێت 0 وەڵامی داوەتەوە؛ قوتابییەک کە خانەکە بەتاڵ جێدەهێڵێت وەڵامی نەداوەتەوە. NULL خانە بەتاڵەکەیە: ناتوانیت بڵێیت یەکسانە بە 0، یان یەکسانە بە خانەیەکی بەتاڵی تر.

Where the analogy stops workingسنووری ئەم نموونەیە

A blank on paper can mean many things (forgotten, refused, not known). In a database a NULL carries no reason at all, which is one reason designers keep NULLs few (why as few NULLs as possible).

خانەیەکی بەتاڵ لەسەر کاغەز دەکرێت چەند واتایەکی هەبێت (لەبیرچوو، ڕەتکرایەوە، نەزانرا). لە NULL هیچ هۆکارێک لەگەڵ خۆی هەڵناگرێت، ئەمەش یەکێکە لە هۆکارەکانی ئەوەی دیزاینەران NULL کەم دەکەنەوە (بۆچی NULL هێندەی دەکرێت کەم بێت).

Quick checkپشکنینی خێراWhat does SELECT name, COALESCE(stock, 0) FROM products WHERE product_id = 6; show for the ThinkPad?SELECT name, COALESCE(stock, 0) FROM products WHERE product_id = 6; بۆ ThinkPad چی پیشان دەدات؟

Sorting the answerڕیزکردنی وەڵامەکە

Without ORDER BY the rows come back in no promised order. SELECT showed ASC (the default) and DESC, and that each column has its own direction. Here is a two-level sort: categories A→Z, and inside each category the most expensive first.

بەبێ ORDER BY بە هیچ ڕیزبەندییەکی بەڵێندراو ناگەڕێنەوە. SELECT ASC (بنەڕەتی) و DESCـی پیشان دا، هەروەها ئەوەی کە هەر ئاڕاستەی خۆی هەیە. ئەمە دوو ئاستییە: جۆرەکان لە A بۆ Z و لە ناو هەر جۆرێکدا گرانترین یەکەم.

SQLRuns in the databaseلە ناو بنکەدراوە کار دەکات
SELECT name, category, price_iqd
FROM products
ORDER BY category, price_iqd DESC;

You can sort by an alias, because ORDER BY is read after the columns are built:

دەتوانیت بەپێی ڕیز بکەیت، چونکە ORDER BY دوای دروستبوونی دەخوێندرێتەوە:

SQLRuns in the databaseلە ناو بنکەدراوە کار دەکات
SELECT name, price_iqd * stock AS stock_value
FROM products
WHERE category IN ('laptop', 'charger')
ORDER BY stock_value DESC;
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 4

The ThinkPad's unknown value (NULL) comes last when sorting from high to low.

نرخە نەزانراوەکەی ThinkPad (NULL) لە ڕیزکردنی بەرز بۆ نزمدا دوایین دێت.

Where do NULLs go? In MySQL (and in SQLite) NULL counts as smaller than every value: first with ASC, last with DESC.

NULL بۆ کوێ دەچێت؟ لە MySQL (و لە SQLite) NULL لە هەموو نرخێک بچووکتر هەژمار دەکرێت: لەگەڵ ASC یەکەم، لەگەڵ DESC دوایین.

SQLRuns in the databaseلە ناو بنکەدراوە کار دەکات
SELECT name, stock FROM products
WHERE category = 'laptop'
ORDER BY stock;
Quick checkپشکنینی خێراSELECT name, stock FROM products WHERE category = 'laptop' ORDER BY stock DESC; — where is the ThinkPad (stock NULL)?SELECT name, stock FROM products WHERE category = 'laptop' ORDER BY stock DESC; — ThinkPad (کۆگا NULL) لە کوێیە؟

SQL Course for Beginners [Full Course]Programming with Mosh · Englishئینگلیزی · 15.5M viewsبینین · 304K likesلایک · Partبەشی 1:14:18–1:24:50 (ofلە 3:10:19)

Mosh's MySQL course chapters: computed columns with AS and DISTINCT, IS NULL, and sorting with ORDER BY and LIMIT.

چەند بەشێکی کۆرسی Mosh: بە AS و DISTINCT، IS NULL و بە و .

Plays 1:14:18-1:24:50 (ORDER BY and LIMIT): several columns, DESC, sorting by an alias, LIMIT with an offset.

لە ⁦1:14:18⁩ تا ⁦1:24:50⁩ پەخش دەبێت (بەشی ORDER BY and LIMIT): بە چەند ، DESC، بە و LIMIT لەگەڵ .

Sorting the answerڕیزکردنی وەڵامەکە

Sorting text, quoted aliases and LIMITڕیزکردنی دەق، نازناوەکانی ناو کۆتەیشن و LIMIT

Three more things about sorting: quotes around an alias, the order of text, and LIMIT.

سێ شتی تر دەربارەی : کۆتەیشن بە دەوری ، ڕیزبەندیی دەق و LIMIT.

Text is sorted by the . In MySQL iPhone 15 sits between Galaxy and Redmi, because small and capital letters are equal; plain SQLite compares character codes, where every capital comes before every small letter, and puts iPhone 15 last.

دەق بەپێی ڕیز دەکرێت. لە MySQLـدا ⁦iPhone 15⁩ لە نێوان Galaxy و Redmiدایە، چونکە پیتی بچووک و گەورە یەکسانن؛ SQLiteـی ئاسایی کۆدی بەراورد دەکات کە تێیدا هەموو پیتێکی گەورە پێش هەموو پیتێکی بچووک دێت و ⁦iPhone 15⁩ دەخاتە کۆتایی.

SQLRuns in the databaseلە ناو بنکەدراوە کار دەکات
SELECT name FROM products WHERE category = 'phone' ORDER BY name;

For a top 3, sort and add LIMIT. LIMIT and OFFSET (for pages of results) are taught in LIMIT, OFFSET and pagination.

بۆ سێ باشترین، ڕیزی بکە و LIMIT زیاد بکە. LIMIT و OFFSET (بۆ پەڕەکانی ئەنجام) لە LIMIT، OFFSET و پەڕەبەندی فێر دەکرێن.

SQLRuns in the databaseلە ناو بنکەدراوە کار دەکات
SELECT name, price_iqd FROM products
ORDER BY price_iqd DESC
LIMIT 3;
Quick checkپشکنینی خێراWhich query lists the three cheapest products?کام سێ هەرزانترین کاڵا پیشان دەدات؟

Exercisesڕاهێنانەکان

Write each query for the shop database, run it in phpMyAdmin, then open the answer. The tasks follow the exercise ideas of the course's textbook chapter, moved to our shop.

هەر بۆ دوکانەکە بنووسە، لە phpMyAdmin جێبەجێی بکە، پاشان وەڵامەکە بکەرەوە. ئەرکەکان بیرۆکەی ڕاهێنانەکانی بەشی کتێبەکەی کۆرسەکەن کە گوازراونەتەوە بۆ دوکانەکەمان.

Exerciseڕاهێنان

1. Show all the information about the customers who live in Sulaimani.

1. هەموو زانیارییەکانی ئەو کڕیارانە پیشان بدە کە لە سلێمانی دەژین.

Show answerوەڵامەکە پیشان بدە
SQLRuns in the databaseلە ناو بنکەدراوە کار دەکات
SELECT * FROM customers WHERE city = 'Sulaimani';
Exerciseڕاهێنان

2. For every phone show the name, the price, the stock and the money on the shelf (price × stock) as a column called Stock value.

2. بۆ هەر مۆبایلێک ناو، قیمەت، ژمارەی کۆگا و ئەو پارەیەی لەسەر ڕەفەکەیە (قیمەت × کۆگا) وەک بە ناوی ⁦Stock value⁩ پیشان بدە.

Show answerوەڵامەکە پیشان بدە
SQLRuns in the databaseلە ناو بنکەدراوە کار دەکات
SELECT name, price_iqd, stock, price_iqd * stock AS `Stock value`
FROM products
WHERE category = 'phone';
Exerciseڕاهێنان

3. List the different categories of products, each once.

3. جۆرە جیاوازەکانی کاڵا، هەر یەکەیان یەک جار، پیشان بدە.

Show answerوەڵامەکە پیشان بدە
SQLRuns in the databaseلە ناو بنکەدراوە کار دەکات
SELECT DISTINCT category FROM products;
Exerciseڕاهێنان

4. During a sale every charger is 5,000 IQD cheaper. Show each charger's name, its price and the price after the discount as after_discount.

4. لە کاتی داشکاندندا هەموو ⁦5,000⁩ دینار هەرزانترە. ناوی هەر ، قیمەتەکەی و قیمەتی دوای داشکاندن وەک after_discount پیشان بدە.

Show answerوەڵامەکە پیشان بدە
SQLRuns in the databaseلە ناو بنکەدراوە کار دەکات
SELECT name, price_iqd, price_iqd - 5000 AS after_discount
FROM products
WHERE category = 'charger';
Exerciseڕاهێنان

5. List the products that cost more than 20,000 and less than 100,000 IQD. Can you write it with BETWEEN?

5. ئەو کاڵایانە پیشان بدە کە زیاتر لە ⁦20,000⁩ و کەمتر لە ⁦100,000⁩ دینارن. دەتوانیت بە BETWEEN بینووسیت؟

Show answerوەڵامەکە پیشان بدە
SQLRuns in the databaseلە ناو بنکەدراوە کار دەکات
SELECT name, price_iqd FROM products
WHERE price_iqd > 20000 AND price_iqd < 100000;

BETWEEN 20000 AND 100000 would include the two end values, which the task excludes. For whole numbers, BETWEEN 20001 AND 99999 gives the same three rows — but the version with > and < says exactly what was asked.

BETWEEN 20000 AND 100000 دوو نرخی سەرەکە دەگرێتەوە کە ئەرکەکە دەریان دەکات. بۆ ، BETWEEN 20001 AND 99999 هەمان سێ دەدات — بەڵام شێوەی > و < ڕێک ئەوە دەڵێت کە داوا کراوە.

Exerciseڕاهێنان

6. List the products that are chargers or headphones — once with OR and once with IN.

6. ئەو کاڵایانە پیشان بدە کە یان — جارێک بە OR و جارێک بە IN.

Show answerوەڵامەکە پیشان بدە
SQLRuns in the databaseلە ناو بنکەدراوە کار دەکات
SELECT name, category FROM products
WHERE category = 'charger' OR category = 'headphones';

SELECT name, category FROM products
WHERE category IN ('charger', 'headphones');
Exerciseڕاهێنان

7. Which products have a stock that has not been counted yet?

7. ژمارەی کۆگای کام کاڵا هێشتا نەژمێردراوە؟

Show answerوەڵامەکە پیشان بدە
SQLRuns in the databaseلە ناو بنکەدراوە کار دەکات
SELECT name, stock FROM products WHERE stock IS NULL;

Not stock = NULL, which finds nothing, and not stock = 0, which would be a counted, empty shelf.

نەک stock = NULL کە هیچ نادۆزێتەوە و نەک stock = 0 کە ڕەفێکی بەتاڵی ژمێردراو دەبێت.

Exerciseڕاهێنان

8. Show the sales where more than one item was sold and the customer paid with fib.

8. ئەو فرۆشتنانە پیشان بدە کە زیاتر لە یەک دانە فرۆشراوە و کڕیار بە fib پارەی داوە.

Show answerوەڵامەکە پیشان بدە
SQLRuns in the databaseلە ناو بنکەدراوە کار دەکات
SELECT sale_id, quantity, payment FROM sales
WHERE quantity > 1 AND payment = 'fib';
Exerciseڕاهێنان

9. Now show the sales where more than one item was sold or the customer paid by card. Why are there more rows than in exercise 8?

9. ئێستا ئەو فرۆشتنانە پیشان بدە کە زیاتر لە یەک دانە فرۆشراوە یان کڕیار بە کارت پارەی داوە. بۆچی لە ڕاهێنانی 8 زیاترن؟

Show answerوەڵامەکە پیشان بدە
SQLRuns in the databaseلە ناو بنکەدراوە کار دەکات
SELECT sale_id, quantity, payment FROM sales
WHERE quantity > 1 OR payment = 'card';

With OR one true side is enough: sales 4 and 10 are single items paid by card, and the cash sales 2, 5 and 14 have more than one item.

لەگەڵ OR یەک لای ڕاست بەسە: فرۆشتنی 4 و ⁦10⁩ یەک دانەن کە بە کارت پارەیان دراوە و فرۆشتنە نەختینەکانی 2، 5 و ⁦14⁩ زیاتر لە یەک دانەیان هەیە.

Exerciseڕاهێنان

10. Show the sales that Lana made not paid with fib.

⁦10⁩. ئەو فرۆشتنانەی Lana پیشان بدە کە بە fib پارەیان نەدراوە.

Show answerوەڵامەکە پیشان بدە
SQLRuns in the databaseلە ناو بنکەدراوە کار دەکات
SELECT sale_id, sold_on, payment FROM sales
WHERE seller = 'Lana' AND payment <> 'fib';
Exerciseڕاهێنان

11. Show Rezan's sales paid by card or with fib. Where do the brackets go, and what happens without them?

⁦11⁩. ئەو فرۆشتنانەی Rezan پیشان بدە کە بە کارت یان بە fib پارەیان دراوە. کەوانەکان لە کوێ دادەنرێن و بەبێ ئەوان چی ڕوودەدات؟

Show answerوەڵامەکە پیشان بدە
SQLRuns in the databaseلە ناو بنکەدراوە کار دەکات
SELECT sale_id, seller, payment FROM sales
WHERE seller = 'Rezan' AND (payment = 'card' OR payment = 'fib');

Without brackets, seller = 'Rezan' AND payment = 'card' OR payment = 'fib' would also return Lana's fib sales, because AND is done first. (Rezan happens to have no card sales.)

بەبێ کەوانە، seller = 'Rezan' AND payment = 'card' OR payment = 'fib' فرۆشتنەکانی fibـی Lanaـش دەگەڕێنێتەوە، چونکە AND یەکەم جێبەجێ دەکرێت. (ڕێکەوت وایە Rezan هیچ فرۆشتنێکی بە کارتی نییە.)

Exerciseڕاهێنان

12. Show the name and price of the Apple product with the column headers product and price. Then: how would you rename the table customers to clients and its column city to town for real?

⁦12⁩. ناو و قیمەتی کاڵای Apple بە سەردێڕی product و price پیشان بدە. پاشان: چۆن بە ڕاستی ناوی customers دەگۆڕیت بۆ clients و ناوی city بۆ town؟

Show answerوەڵامەکە پیشان بدە
SQLRuns in the databaseلە ناو بنکەدراوە کار دەکات
SELECT name AS product, price_iqd AS price
FROM products
WHERE brand = 'Apple';

AS renames only in the answer. Renaming in the table itself changes the structure, so it is an ALTER/RENAME statement:

AS تەنها لە وەڵامەکەدا ناو دەگۆڕێت. گۆڕینی ناو لە خودی پێکهاتەکە دەگۆڕێت، بۆیە فەرمانێکی ALTER/RENAMEـە:

SQLRuns in the databaseلە ناو بنکەدراوە کار دەکات
RENAME TABLE customers TO clients;                 -- MySQL / MariaDB
ALTER TABLE clients RENAME COLUMN city TO town;    -- MySQL 8, MariaDB 10.5.2+, SQLite

-- Old MariaDB 10.4 (XAMPP 8.2 and older) has no RENAME COLUMN; there use instead:
-- ALTER TABLE clients CHANGE city town VARCHAR(30) NOT NULL;

Renaming breaks every PHP page and query that still uses the old names, so do it before the website is built, not after.

گۆڕینی ناو هەموو پەڕەیەکی PHP و تێک دەدات کە هێشتا ناوە کۆنەکان بەکار دەهێنێت، بۆیە پێش دروستکردنی ماڵپەڕەکە ئەنجامی بدە، نەک دوای.

Exerciseڕاهێنان

13. List all products by name from Z to A; when two names were equal, the cheaper one should come first.

⁦13⁩. هەموو کاڵاکان بەپێی ناو لە Z بۆ A ڕیز بکە؛ ئەگەر دوو ناو وەک یەک بوون، هەرزانترەکە دەبێت یەکەم بێت.

Show answerوەڵامەکە پیشان بدە
SQLRuns in the databaseلە ناو بنکەدراوە کار دەکات
SELECT name, price_iqd FROM products
ORDER BY name DESC, price_iqd;

DESC belongs to name only; price_iqd uses the default ASC. In plain SQLite iPhone 15 would come first, because a small i sorts after every capital letter there.

DESC تەنها هی nameـە؛ price_iqd ASCـی بنەڕەتی بەکار دەهێنێت. لە SQLiteـی ئاسایی ⁦iPhone 15⁩ یەکەم دەبوو، چونکە لەوێ iـی بچووک دوای هەموو پیتێکی گەورە ڕیز دەکرێت.

Common mistakesهەڵە باوەکان

The basic mistakes — curly quotes, text without quotes (WHERE brand = Samsung), UPDATE or DELETE without WHERE — are in Common mistakes. These are the new ones of this lesson:

هەڵە بنەڕەتییەکان — کۆتەیشنی چەماوە، دەقی بێ کۆتەیشن (WHERE brand = Samsung)، UPDATE یان DELETE بەبێ WHERE — لە هەڵە باوەکاندان. ئەمانە هەڵە نوێکانی ئەم وانەیەن:

Mistakes to avoid in WHERE and ORDER BYئەو هەڵانەی لە WHERE و ⁦ORDER BY⁩ خۆتیان لێ دەپارێزیت
MistakeهەڵەWhat happensچی ڕوودەداتFixچارەسەر
WHERE stock = NULLNo rows, never an errorهیچ نایەت و هەڵەش ناداتWHERE stock IS NULL
… AND brand = 'Samsung' OR brand = 'Xiaomi'AND is done first; unwanted rows slip inAND یەکەم جێبەجێ دەکرێت؛ دێنە ژوورەوە… AND (brand = 'Samsung' OR brand = 'Xiaomi')
BETWEEN 600000 AND 250000Empty set: the low value must come first⁦Empty set⁩: نرخی نزم دەبێت یەکەم بێتBETWEEN 250000 AND 600000
WHERE name = 'Redmi%'= treats % as a normal character= % وەک ئاسایی دادەنێتWHERE name LIKE 'Redmi%'
WHERE brand NOT IN ('Samsung', 'Xiaomi')Rows with a NULL brand silently disappear بە براندی NULL بێدەنگ ون دەبن… OR brand IS NULL
WHERE stock_value > 2500000MySQL: Unknown column — the alias does not exist yetMySQL: ⁦Unknown column⁩ — هێشتا بوونی نییەWHERE price_iqd * stock > 2500000
ORDER BY 'Stock value'Sorts by a constant text: no sorting at allبەپێی دەقێکی نەگۆڕ ڕیز دەکات: هیچ ڕیزکردنێک نییەORDER BY `Stock value`
AS Stock valueSyntax error: the space ends the alias: بۆشاییەکە کۆتایی پێدەهێنێتAS `Stock value` or AS stock_value

Summary and reviewپوختە و پێداچوونەوە

  • The list after SELECT chooses and computes columns; AS names them (backticks for spaces in MySQL). DISTINCT removes repeated rows of the answer.
  • WHERE keeps the rows where the condition is true: = <> != < <= > >= on numbers, quoted text and quoted dates. = compares the whole value.
  • NOT first, then AND, then OR — write brackets whenever AND and OR are mixed.
  • BETWEEN a AND b includes both ends (low value first); IN (…) is a list of ORs; NOT IN loses NULL rows, and a NULL in the list makes it return nothing.
  • LIKE: % = any number of characters, _ = exactly one. MySQL's default collations and SQLite's LIKE ignore letter case; SQLite's = does not. Access uses * and ?.
  • NULL is unknown: test it with IS NULL / IS NOT NULL, never = NULL; arithmetic with NULL gives NULL; COALESCE gives a default.
  • ORDER BY sorts by several columns or by an alias (backticks, not single quotes); NULLs come first with ASC and last with DESC; LIMIT cuts the list.
  • لیستی دوای SELECT هەڵدەبژێرێت و دەیانژمێرێت؛ AS ناویان لێ دەنێت (لە MySQLـدا backtick بۆ بۆشایی). DISTINCT وەڵامەکە لادەبات.
  • WHERE ئەو دەهێڵێتەوە کە تێیاندا ڕاستە: = <> != < <= > >= لەسەر ژمارە، دەقی ناو کۆتەیشن و بەرواری ناو کۆتەیشن. = هەموو نرخەکە بەراورد دەکات.
  • یەکەم NOT، پاشان AND، پاشان OR — هەر کاتێک AND و OR تێکەڵ بوون کەوانە بنووسە.
  • BETWEEN a AND b هەردوو سەر دەگرێتەوە (یەکەم نرخی نزم)؛ IN (…) لیستێکی ORـە؛ NOT IN NULL لە دەست دەدات و NULL لە ناو لیستەکەدا وا دەکات هیچ نەگەڕێنێتەوە.
  • LIKE: % = هەر ژمارەیەک ، _ = ڕێک یەک. بنەڕەتییەکانی MySQL و LIKEـی SQLite گەورە و بچووکیی پیت پشتگوێ دەخەن؛ =ـی SQLite نا. Access * و ? بەکار دەهێنێت.
  • NULL نەزانراوە: بە IS NULL / IS NOT NULL تاقی بکەرەوە، هەرگیز بە = NULL نا؛ هەر ژماردنێک NULLـی تێدا بێت ئەنجامەکەی NULLـە؛ COALESCE دەدات.
  • ORDER BY بەپێی چەند یان بەپێی ڕیز دەکات (backtick، نەک کۆتەیشنی تاک)؛ NULL لەگەڵ ASC یەکەم و لەگەڵ DESC دوایین دێت؛ LIMIT لیستەکە کورت دەکاتەوە.
Review questionsپرسیارەکانی پێداچوونەوە
What is the difference between WHERE brand = 'Xiaomi' and WHERE brand LIKE 'X%'?جیاوازیی نێوان WHERE brand = 'Xiaomi' و WHERE brand LIKE 'X%' چییە؟

The first keeps only the brand that is exactly Xiaomi. The second keeps every brand that starts with X, whatever follows.

یەکەمیان تەنها ئەو براندە دەهێڵێتەوە کە ڕێک Xiaomiـە. دووەمیان هەموو براندێک دەهێڵێتەوە کە بە X دەست پێدەکات، دوای ئەوە هەرچی بێت.

Why does WHERE stock = NULL return no rows?بۆچی WHERE stock = NULL هیچ تۆمارێک ناگەڕێنێتەوە؟

Comparing anything with NULL gives NULL (unknown), and WHERE keeps only rows where the condition is true. IS NULL is the test for a missing value.

ئەنجامی بەراوردکردنی هەر شتێک لەگەڵ NULL هەر NULLـە (نەزانراو) و WHERE تەنها ئەو دەهێڵێتەوە کە تێیاندا ڕاستە. IS NULL تاقیکردنەوەی نرخی ونە.

Rewrite price_iqd >= 18000 AND price_iqd <= 30000 with BETWEEN. Which products does it find?price_iqd >= 18000 AND price_iqd <= 30000 بە BETWEEN بنووسەرەوە. کام کاڵا دەدۆزێتەوە؟

price_iqd BETWEEN 18000 AND 30000 — the three chargers (18,000, 25,000 and 30,000 IQD); both ends are included.

price_iqd BETWEEN 18000 AND 30000 — سێ (⁦18,000⁩، ⁦25,000⁩ و ⁦30,000⁩ دینار)؛ هەردوو سەرەکە لەگەڵیدان.

Why can you ORDER BY an alias but not use it in WHERE?بۆچی دەتوانیت ORDER BY بەپێی نازناوێک بکەیت بەڵام لە WHEREـدا بەکاری نەهێنیت؟

SQL works out WHERE before it builds the columns of the answer, and ORDER BY after. When WHERE runs, the alias does not exist yet.

SQL پێش دروستکردنی وەڵامەکە WHERE جێبەجێ دەکات و ⁦ORDER BY⁩ دوای ئەوە. کاتێک WHERE کار دەکات، هێشتا بوونی نییە.

Videoڤیدیۆ

Watch a videoسەیری ڤیدیۆیەک بکە

A video that viewers liked a lot and praised in their comments, chosen for this lesson.ڤیدیۆیەک کە بینەران زۆریان پێ خۆش بووە و لە کۆمێنتەکانیاندا ستایشیان کردووە، بۆ ئەم وانەیە هەڵبژێردراوە.

Where Clause in MySQL | Beginner MySQL SeriesAlex The Analyst · Englishئینگلیزی · 420K viewsبینین · 6.4K likesلایک

Filtering rows with WHERE in MySQL: comparison operators, numbers, text and dates, AND, OR and NOT, and patterns with LIKE using % and _.

بە لە : بۆ ژمارە، دەق و بەروار، AND، OR و NOT، هەروەها LIKE بە % و _.

Whole video, MySQL Workbench: comparison operators 1:08, types 2:58, AND/OR/NOT 4:28, LIKE with % and _ 7:46.

هەموو ڤیدیۆکە، لە Workbench: لە ⁦1:08⁩، لە ⁦2:58⁩، AND/OR/NOT لە ⁦4:28⁩ و LIKE بە % و _ لە ⁦7:46⁩.

Lesson complete!وانەکە تەواو بوو!

Well done. Review the key terms, then go on to the next lesson.دەستخۆش. سەیرێکی زاراوە سەرەکییەکان بکەرەوە، پاشان بڕۆ بۆ وانەی داهاتوو.

Key termsزاراوە سەرەکییەکان

Next lessonوانەی داهاتوو

SQL Functions, Aggregates and GROUP BYکردارەکانی SQL، کردارەکانی کۆکردنەوە و ⁦GROUP BY⁩

References and further readingسەرچاوەکان و خوێندنەوەی زیاتر

This lecture is a first edition. The Kurdish text and terminology are waiting for review by Kurdish IT teachers.ئەم وانەیە چاپی یەکەمە. دەقە کوردییەکە و زاراوەکانی چاوەڕێی پێداچوونەوەی مامۆستایانی کوردی بواری IT ن.