NULL means the value is unknown, not zero and not an empty string. That changes how comparisons and arithmetic behave.
Any arithmetic with NULL gives NULL, and NULL = NULL is not TRUE. Test emptiness with IS NULL. Open in SQL Lab
Customers without an email. Open in SQL Lab
COALESCE returns the first non-NULL value. Open in SQL Lab
Text functions and casting
|| concatenates text in SQLite and PostgreSQL. Open in SQL Lab
CAST converts the type. Open in SQL Lab
For advanced readers Three-valued logic and types
SQL has three truth values: TRUE, FALSE and UNKNOWN, and WHERE keeps only TRUE. SQLite is flexible about types while PostgreSQL and SQL Server are strict; prefer explicit CAST. Concatenation: || in SQLite, PostgreSQL and Oracle, CONCAT in MySQL, + or CONCAT in SQL Server.
Exercise 1 — Show the name and city of customers who have no email.
Use IS NULL, not = NULL.
Exercise 2 — Show one column label formatted as: name then the city in uppercase in parentheses, e.g. Ahmed Ali (CAIRO).
Concatenate with || and add the space and parentheses.
- NULL = unknown value; test with IS NULL.
- COALESCE substitutes empty values.
- CAST converts types and || joins text.
Want an expert to do it for you?
Gomaa Intelligence turns your data into clear reports and decisions. Tell us your problem and we will reply.