SQL Basics

SQL Introduction

Learn what SQL is, why databases are essential, and how SQL powers every major application.

What is SQL?

SQL stands for Structured Query Language. SQL lets you access and manipulate databases. SQL became a standard of the American National Standards Institute (ANSI) in 1986, and of the International Organization for Standardization (ISO) in 1987.

What Can SQL Do?

  • SQL can execute queries against a database
  • SQL can retrieve data from a database
  • SQL can insert, update, and delete records
  • SQL can create new databases and tables
  • SQL can set permissions on tables, procedures, and views

SQL Databases

SQL is used to interact with many popular database systems:

  • PostgreSQL — Advanced open-source database
  • MySQL — World's most popular open-source database
  • SQLite — Lightweight embedded database
  • Microsoft SQL Server — Enterprise database
  • Oracle — Enterprise database

Key Concepts

  • Database — Organized collection of data
  • Table — Data organized in rows and columns
  • Row — A single record in a table
  • Column — A field in a record

Example

sql
-- Basic SQL query
SELECT * FROM users;

-- Select specific columns
SELECT name, email, created_at
FROM users;

-- With a condition
SELECT name, email
FROM users
WHERE active = true;

-- Count records
SELECT COUNT(*) AS total_users
FROM users;

-- Order results
SELECT name, score
FROM leaderboard
ORDER BY score DESC
LIMIT 10;

Want to run this code interactively?

Try in Compiler