SQL Fundamentals
SQL (Structured Query Language) is the standard language for querying and manipulating data in relational databases. It covers SELECT statements, filtering, joins, aggregation, subqueries, data modification, and the declarative approach to describing what data you want rather than how to get it.
itProgramming languages | OpenSkills.info
Course pathWalk it in order
Look it upDip in anytime
Go furtherLeaves this page
Don't Panic
Don't Panic — SQL Fundamentals
SQL is the language for asking a relational database to arrange and change information. You say what answer you need; the database chooses the route through the data. That is a useful delegation, because databases have better attendance than a notebook of hand-written pointer chasing.
The furniture is tables: rows hold records, columns hold named and typed values. Tables become a database rather than a pile of spreadsheets when keys connect them. A primary key identifies a row; a foreign key says that one row refers to another. An order can therefore name its customer without carrying a stale copy of the customer's email around like a folded note in a pocket.
The most important habit is to ask what one result row means before writing a query. A join combines related tables, but a one-to-many relationship can make one customer appear once for every order. That is correct when the question is about orders and disastrous when a total is supposed to be per customer. SQL will faithfully count the rows it has been handed. It is not being difficult; it is being literal, which is its preferred hobby.
The language arrives in several departments. CREATE and ALTER define
structure. INSERT, UPDATE, and DELETE change rows. SELECT reads and
reshapes them. GRANT and REVOKE control access. BEGIN, COMMIT, and
ROLLBACK make a transaction: a group of changes that all survive or
all disappear. Constraints add the database's own veto: missing, duplicate,
negative, or orphaned values can be rejected where they enter.
Two parts require respect. NULL is not an ordinary empty value; its comparisons can be unknown, so an innocent-looking filter can omit rows. And SQL is a standard with regional accents. PostgreSQL, MySQL, SQL Server, Oracle Database, and SQLite share the core ideas, then add different syntax and features. Learn the tables, keys, joins, grouping, constraints, and transactions first. The accents make more sense after that.
Read the Cheatsheet when a clause, join, or constraint needs a compact reminder. Use the Practice Reference for query shapes and the Exercise to make a small database prove its promises. The Timeline explains how this shared language acquired so many extensions; the Landscape shows where its dialects live. The rest of SQL is detail, although it has accumulated a rather impressive amount of detail over the decades.
Where this skill leads
Relevant careers
See how this topic contributes to broader role-level skill maps.
Sources
- https://www.postgresql.org/docs/current/tutorial-sql.html
Supports
- DDL vs DML distinction and what each covers
- Creating tables, inserting rows, querying, updating, deleting
- The basic shape of a SELECT statement
- https://www.postgresql.org/docs/current/sql-commands.html
Supports
- Categorization of SQL commands into DDL, DML, transaction control, access control, and other groups
- Quiz answer distinguishing CREATE/ALTER (DDL) from INSERT/DELETE (DML), GRANT/REVOKE (DCL), and BEGIN/COMMIT (TCL)
- https://www.postgresql.org/docs/current/queries-table-expressions.html
Supports
- INNER, LEFT, RIGHT, FULL, and CROSS JOIN semantics
- ON vs. WHERE clause evaluation order and its effect on outer joins
- USING and NATURAL JOIN shorthand
- GROUP BY and HAVING behavior and the FROM/WHERE/GROUP BY/HAVING/SELECT/ORDER BY evaluation order
- Quiz answers on LEFT JOIN NULL-filling and WHERE-after-outer-join behavior
- Exercise joins, grouping, and HAVING checks
- https://www.postgresql.org/docs/current/ddl-constraints.html
Supports
- PRIMARY KEY, FOREIGN KEY, UNIQUE, CHECK, and NOT NULL constraint semantics
- Foreign key referential actions (CASCADE, RESTRICT, NO ACTION, SET NULL, SET DEFAULT)
- UNIQUE allowing multiple NULLs by default
- Quiz answers on what PRIMARY KEY and FOREIGN KEY guarantee
- Exercise constraint checks
- https://www.postgresql.org/docs/current/tutorial-transactions.html
Supports
- Definition of a transaction and atomicity
- BEGIN/COMMIT/ROLLBACK behavior and savepoints
- Implicit per-statement transactions
- Quiz answer on why transactions matter for a bank transfer
- Exercise rollback check
- https://www.postgresql.org/docs/current/indexes-intro.html
Supports
- Why indexes speed up lookups vs. full table scans
- CREATE INDEX basic usage
- Write-overhead tradeoff of maintaining indexes
- Quiz answer on index write cost with frequent INSERTs
- https://www.postgresql.org/docs/current/functions-subquery.html
Supports
- EXISTS, IN, NOT IN, ANY/SOME, ALL subquery expression semantics
- NULL handling and three-valued logic in NOT IN
- Quiz answer on NOT IN silently returning no rows when the subquery contains NULL
- https://www.postgresql.org/docs/current/datatype.html
Supports
- Major SQL data type categories (numeric, character, date/time, boolean, JSON, and others)
- https://www.sqlite.org/lang.html
Supports
- SQLite as a representative example of vendor SQL dialect variation
- https://dev.mysql.com/doc/refman/8.4/en/
Supports
- MySQL as a representative example of vendor SQL dialect variation
- https://en.wikipedia.org/wiki/SQL
Supports
- SQL's origin at IBM, SEQUEL naming, Codd's relational model, System R
- ANSI SQL-86 and ISO/IEC 9075:1987 standardization timeline
- Later standard revisions (SQL-92 through SQL:2023) and their headline features
- DDL/DML/DQL/DCL sublanguage terminology
- Known limitations: duplicate rows, ordered results, three-valued NULL logic, incomplete standards compliance, vendor divergence
- Quiz answers on declarative nature and incomplete standard compliance across vendors
- SQL timeline milestones from ANSI SQL-86 through SQL:2016
- https://en.wikipedia.org/wiki/Database_normalization
Supports
- Definitions of 1NF, 2NF, 3NF, and BCNF
- Purpose of normalization (redundancy reduction, anomaly prevention)
- Denormalization tradeoff for read-heavy systems
- Quiz answer distinguishing a 2NF-but-not-3NF transitive dependency from a 1NF or 2NF violation
- https://www.sqlite.org/cli.html
Supports
- Starting sqlite3 with a database filename
- Interactive evaluation of SQL statements for the exercise
- https://docs.oracle.com/en/database/oracle/oracle-database/12.2/sqlrf/History-of-SQL.html
Supports
- Codd's 1970 relational-model paper
- IBM development of SEQUEL
- Oracle V2 as the first commercially available SQL implementation in 1979
- https://dl.acm.org/doi/10.1145/800296.811515
Supports
- 1974 SEQUEL language description for System R
- https://docs.oracle.com/cd/A57673_01/DOC/server/doc/SQL73/ch1.htm
Supports
- ANSI X3.135-1992 and the SQL-92 revision
- https://www.iso.org/standard/76583.html
Supports
- ISO/IEC 9075-1:2023 publication date and sixth framework edition
- SQL property graph queries in the ISO/IEC 9075 standard family
- https://www.postgresql.org/about/licence/
Supports
- PostgreSQL's permissive open-source license and no-fee availability
- https://www.mysql.com/products/community/
Supports
- MySQL Community Edition as a free GPL distribution
- MySQL editions and product context
- https://learn.microsoft.com/en-us/sql/sql-server/editions-and-components-of-sql-server-2019
Supports
- SQL Server edition lineup including free Express and non-production Developer editions
- https://docs.oracle.com/cd/F82042_01/xeinl/database-free-installation-guide-linux.pdf
Supports
- Oracle Database Free as a free edition
- https://sqlite.org/index.html?lang=en
Supports
- SQLite's public-domain source and free use
