Skip to main content
Albero Academy

CRUD & Querying

Insert, read, update and delete rows, then filter, sort, paginate and group results — the daily bread of database work.

Chapter 2MySQL15 min readBeginner friendly
  • #MySQL
  • #CRUD
  • #Queries

CRUD — Create, Read, Update, Delete — is what almost every database operation boils down to. This chapter is the practical core: putting rows in, getting the right rows out, and changing or removing them safely.

INSERT — create rows

adding data
INSERT INTO students (name, email, package)
VALUES ('Aanya', 'aanya@example.com', 6.50);
-- Several rows at once
INSERT INTO students (name, package) VALUES
('Rohan', 8.00),
('Priya', 7.25);

SELECT & WHERE — read rows

SELECT chooses columns; WHERE filters rows. List only the columns you need — SELECT * is convenient but wasteful in real queries:

filtering
SELECT name, package FROM students
WHERE package > 6
AND enrolled >= '2026-01-01';
-- Useful WHERE operators
WHERE name LIKE 'A%' -- starts with A
WHERE package BETWEEN 5 AND 8 -- inclusive range
WHERE status IN ('placed','offer') -- any of a list
WHERE email IS NULL; -- missing value

Sorting & paging

order & limit
SELECT name, package FROM students
ORDER BY package DESC -- highest first
LIMIT 10; -- top 10
-- Pagination: page 3 of 10-row pages
SELECT * FROM students ORDER BY id LIMIT 10 OFFSET 20;

GROUP BY — summarise

Aggregate rows into groups and compute per-group values. WHERE filters rows before grouping; HAVING filters the groups after:

aggregation
SELECT programme, COUNT(*) AS students, AVG(package) AS avg_pkg
FROM students
WHERE package > 0
GROUP BY programme
HAVING students >= 5
ORDER BY avg_pkg DESC;

UPDATE & DELETE — change & remove

modifying data
UPDATE students SET package = 9.0 WHERE id = 1;
DELETE FROM students WHERE enrolled IS NULL;

Practice

Insert 8 students, then write queries for: the top 3 by package, the count of students per programme, all students enrolled this year, and an update that gives everyone in one programme a raise. Test each risky change with a matching SELECT first.

Key takeaways

  1. 01INSERT adds rows (single or multiple); SELECT…WHERE reads and filters them.
  2. 02Filter with LIKE, BETWEEN, IN and IS NULL; select only the columns you need.
  3. 03ORDER BY sorts; LIMIT/OFFSET paginate.
  4. 04GROUP BY summarises into groups; WHERE filters rows, HAVING filters the resulting groups.
  5. 05Always include a WHERE on UPDATE/DELETE — preview it as a SELECT first.