Academic Block

SQL Introduction
Browse topics from the sidebar, or search with Ctrl + K

What is SQL?

SQL (Structured Query Language) is the standard language used to create, read, update, and delete data stored in relational databases. Where a spreadsheet stores data in flat sheets, a relational database organizes it into linked tables, and SQL is how you ask questions of — and make changes to — that data.

Why SQL is used

Almost every application that stores structured data — from banking systems to e-commerce sites to internal admin tools — relies on a relational database underneath. SQL gives every one of them a common, declarative way to retrieve exactly the data needed, filter and combine it across tables, and keep it consistent, without each application inventing its own storage format.

Features of SQL

  • Declarative querying — you describe what data you want, not how to fetch it
  • Joins across multiple related tables
  • Aggregation (COUNT, SUM, AVG, GROUP BY)
  • Filtering and sorting (WHERE, ORDER BY)
  • Data definition (CREATE, ALTER, DROP)
  • Transactions for safe, all-or-nothing updates

Advantages of SQL

  • Widely supported — nearly every relational database understands it
  • Efficient at handling large, structured datasets
  • Enforces data integrity through types, keys, and constraints
  • Mature tooling, documentation, and community knowledge
  • Readable, close to plain-English syntax

How SQL works with data

Data lives in tables made up of rows and columns. A statement like SELECT targets one or more tables, optionally filters rows with WHERE, and returns the matching data as a result set — the same shape you see in the query results below.

SQL syntax

SELECT column1, column2
FROM table_name
WHERE condition
ORDER BY column1;

Example: Basic SELECT

SELECT name, department, salary
FROM employees
WHERE salary > 60000
ORDER BY salary DESC;

Example: GROUP BY

SELECT department, COUNT(*) AS headcount, AVG(salary) AS avg_salary
FROM employees
GROUP BY department
ORDER BY avg_salary DESC;

Ways to run SQL

  1. Directly in a database client or admin tool (e.g. psql, MySQL Workbench)
  2. Embedded in application code via a database driver or ORM
  3. In-browser, as in the live editor on this page (via SQLite compiled to WebAssembly)

SQL dialects

Dialect Database Notable for
T-SQL SQL Server Procedural extensions, error handling
PL/pgSQL PostgreSQL Rich type system, extensibility
SQLite dialect SQLite Lightweight, file-based, used in this page’s editor
MySQL dialect MySQL / MariaDB Widely used in web applications

Best practices

  • Select only the columns you need, not SELECT *, in production code
  • Filter early with WHERE rather than pulling everything and filtering in code
  • Use meaningful table and column names
  • Index columns you filter or join on frequently
  • Wrap multi-step changes in a transaction

Try it yourself — click Test My Code on any example above to open a live editor that runs real SQL against a sample employees table.

Ctrl + Enter to run code in the editor Esc to close the editor

🧪 Test Your SQL Code

Edit the SQL code on the left and click “Run Code” to see the result on the right.

📝 SQL Code
👁️ Preview (query result)

Click “Run Code” to see the result here.