SQL Not
NOT reverses a logical condition. It can make a filter read naturally, but the way it interacts with missing values is worth learning early. Unknown is not the same as false.
Understand the idea
This query excludes cancelled orders. The status column is required in our sample schema, so every row can be tested directly. If a nullable column is involved, NOT does not automatically include its missing values. For a complex condition, write parentheses around the part you want to reverse.
Where to try it
Run this example in the SQL playground. The lesson link loads the shop tables and sample rows before this query. Select Run when you are ready. Every run starts fresh, so your changes do not affect the website or a previous run.
SQLite sample data · MySQL / MariaDB sample data · See the sample tables
A worked example
SELECT order_id, status
FROM orders
WHERE NOT (status = 'cancelled')
ORDER BY order_id;
Read the result
Orders 101, 102, and 103 remain. The two paid orders and the pending order are all different from cancelled. Order 104 is excluded.
Try one change
Write the same filter using <>. Then decide whether pending orders should belong in a report described as completed sales.