60 Mins beginner
5. Basic SQL — Your First Queries
Bridge Module 5
Basic SQL — Your First Queries
SQL (Structured Query Language) is how you communicate with relational databases. In this module, you'll learn the four basic operations: SELECT, INSERT, UPDATE, and DELETE. You can copy these SQL statements and run them in any database tool (like PostgreSQL, MySQL, or SQLite).
📝 The Four Basic Operations (CRUD)
CREATE →
Add new data
INSERTAdd new data
READ →
Query data
SELECTQuery data
UPDATE →
Modify data
UPDATEModify data
DELETE →
Remove data
DELETERemove data
📖 SELECT — Reading Data
-- Select all columns from the users table
SELECT * FROM users;
-- Select only specific columns
SELECT name, email FROM users;
-- Filter with WHERE
SELECT * FROM users WHERE age > 18;
-- Multiple conditions
SELECT * FROM users WHERE age > 18 AND city = 'Accra';
-- Sort results (DESC = descending, ASC = ascending)
SELECT * FROM users ORDER BY created_at DESC;
-- Limit results (pagination)
SELECT * FROM users LIMIT 10 OFFSET 20;
Example Outputid | name | email | age
----------------------------------------
1 | Alice | alice@example.com | 25
2 | Bob | bob@example.com | 32
3 | Charlie | charlie@example.com| 28
✏️ INSERT — Adding Data
-- Insert a single row
INSERT INTO users (name, email, age)
VALUES ('Alice', 'alice@example.com', 25);
-- Insert multiple rows at once
INSERT INTO users (name, email, age) VALUES
('Bob', 'bob@example.com', 32),
('Charlie', 'charlie@example.com', 28);
🔄 UPDATE — Modifying Data
-- Update a specific user
UPDATE users
SET age = 26, email = 'alice.new@example.com'
WHERE name = 'Alice';
-- ⚠️ WARNING: Without WHERE, this updates EVERY row!
-- UPDATE users SET age = 30; -- DON'T DO THIS!
🗑️ DELETE — Removing Data
-- Delete a specific user
DELETE FROM users WHERE name = 'Charlie';
-- ⚠️ WARNING: Without WHERE, this deletes EVERY row!
-- DELETE FROM users; -- DON'T DO THIS!
🚨 THE MOST IMPORTANT RULE: Always use
WHERE with UPDATE and DELETE. Forgetting WHERE will modify or delete EVERY row in your table!💻 Next Steps
In the next module, you'll learn more advanced SQL: creating tables, primary keys, foreign keys, relationships, and JOINs. You'll be able to copy those SQL statements to your own database to practice.
Knowledge Check
Ready to test your understanding of 5. Basic SQL — Your First Queries?