PyCodeItPython trace & interview prep
SQL Mastery Hub/sql fundamentals
SQL Analytics TrackWebAssembly SQLite Playground

Database & SQL Fundamentals

Master relational database concepts, SQL command pillars (DQL, DDL, DML, DCL), data types, and foundational SQL syntax.

SQL Query Architecture & Optimization Guide

SQL Fundamentals establish the foundational declarative grammar of relational databases. You declare what columns and tables you need using SELECT and FROM statements, filter rows using WHERE predicates, and handle three-valued logic (TRUE, FALSE, UNKNOWN) caused by NULL values.

Core Projection and Predicate Lifecycle

The engine begins by locating the target table in the FROM clause, tests each candidate row against the boolean predicates in WHERE, and finally projects the requested columns or computed expressions in SELECT. Because SELECT runs last, column aliases are not available in WHERE clauses.

NULL Comparison and Alias Traps

A common beginner error is testing for missing data with WHERE column = NULL. In SQL, any equality comparison with NULL evaluates to UNKNOWN (falsy). Always use IS NULL or IS NOT NULL. Additionally, never attempt to reuse SELECT column aliases in WHERE filters.

Interactive WebAssembly SQL Playground

Frequently Asked Questions on Database & SQL Fundamentals

Why does SELECT column = NULL return nothing or UNKNOWN in SQL?

In ANSI SQL, NULL represents an unknown or missing value rather than a literal zero or empty string. Standard equality operators (= or !=) evaluate to UNKNOWN when compared against NULL. Always use IS NULL or IS NOT NULL for accurate checks.

Why can I not use column aliases defined in SELECT inside the WHERE clause?

The WHERE clause is evaluated before the SELECT clause in SQL execution order. Because column aliases are created during the SELECT phase, the database engine does not yet recognize them when evaluating WHERE conditions.

What is the difference between CHAR, VARCHAR, and TEXT data types?

CHAR is fixed-length, padding unused space with blank spaces. VARCHAR is variable-length up to a specified character limit. TEXT stores variable-length strings without requiring a predefined length boundary.