SQL Basics: SELECT, INSERT, UPDATE, DELETE
SQL is the universal language of relational databases. Learn the four essential commands that let you talk to any database.
What is SQL?
SQL is how you talk to a database.
Just like you ask a librarian “Show me all books by this author” or “Add this new book to the shelf,” SQL is the language you use to ask a database questions and give it instructions. Every relational database understands SQL.
There are four basic things you can say: SELECT (show me data), INSERT (add new data), UPDATE (change existing data), and DELETE (remove data).
The four core SQL statements
SELECT — read data
The most common SQL statement. It retrieves data from one or more tables.
-- All drivers
SELECT * FROM Drivers;
-- Specific columns with a filter
SELECT Name, LicenceClass
FROM Drivers
WHERE HireDate > '2024-01-01';
-- Count deliveries per driver
SELECT DriverID, COUNT(*) AS TotalDeliveries
FROM Deliveries
GROUP BY DriverID;
Key clauses:
SELECT— which columns to returnFROM— which table(s) to queryWHERE— filter rowsORDER BY— sort resultsGROUP BY— group rows for aggregation (COUNT, SUM, AVG)JOIN— combine rows from multiple tables
INSERT — add new data
-- Add a new driver
INSERT INTO Drivers (DriverID, Name, LicenceClass, HireDate)
VALUES ('D003', 'Ana Reyes', 'Class 5', '2026-04-20');
UPDATE — change existing data
-- Update a driver's licence class
UPDATE Drivers
SET LicenceClass = 'Class 2'
WHERE DriverID = 'D003';
Always include a WHERE clause — without it, every row gets updated.
DELETE — remove data
-- Remove a driver
DELETE FROM Drivers
WHERE DriverID = 'D003';
Always include a WHERE clause — without it, every row gets deleted.
SQL statement categories
| Feature | DML | DDL | DCL |
|---|---|---|---|
| Full name | Data Manipulation Language | Data Definition Language | Data Control Language |
| Purpose | Work with data | Define structure | Manage access |
| Key statements | SELECT, INSERT, UPDATE, DELETE | CREATE, ALTER, DROP | GRANT, REVOKE, DENY |
| Example | SELECT * FROM Drivers | CREATE TABLE Drivers (...) | GRANT SELECT ON Drivers TO analyst_role |
DDL examples
-- Create a new table
CREATE TABLE Products (
ProductID INT PRIMARY KEY,
Name VARCHAR(100) NOT NULL,
Price DECIMAL(10,2)
);
-- Add a column to an existing table
ALTER TABLE Products
ADD Category VARCHAR(50);
-- Delete a table entirely
DROP TABLE Products;
JOINs — connecting tables
The real power of SQL is joining tables. A JOIN combines rows from two tables based on a related column.
-- Show each delivery with the driver's name
SELECT d.DeliveryID, d.Destination, dr.Name AS DriverName
FROM Deliveries d
JOIN Drivers dr ON d.DriverID = dr.DriverID;Common join types:
- INNER JOIN — only rows that match in both tables
- LEFT JOIN — all rows from the left table, matched rows from the right (nulls if no match)
- RIGHT JOIN — all rows from the right table, matched rows from the left
- FULL JOIN — all rows from both tables
Exam tip: SQL statement matching
The exam gives you a task and asks which SQL statement to use:
- “Retrieve all orders from last month” → SELECT with WHERE
- “Add a new customer record” → INSERT
- “Change a customer’s email address” → UPDATE
- “Remove cancelled orders” → DELETE
- “Create a new table for products” → CREATE TABLE (DDL)
- “Give the analyst team read access” → GRANT (DCL)
Flashcards
Knowledge check
Tom wants to see all deliveries that were completed in April 2026, sorted by date. Which SQL statement type does he need?
Jake needs to create a new Products table in his CloudPulse database. Which category of SQL does this fall under?
🎬 Video coming soon
Next up: Database Objects: Views, Indexes & More — beyond tables, what else lives inside a database?