Lesson 2
SQL Basics
Master the essential SQL commands for managing relational databases.
Lesson content
SQL Fundamentals
SQL (Structured Query Language) is a standardized language used to interact with relational databases. It allows you to create tables, insert data, update records, and retrieve information.
CRUD Operations
- CREATE: Insert new records into a table
- READ: Retrieve data from tables using SELECT
- UPDATE: Modify existing records
- DELETE: Remove records from tables
Common SQL Clauses
- SELECT: Retrieve columns
- WHERE: Filter records based on conditions
- ORDER BY: Sort results
- JOIN: Combine data from multiple tables
- GROUP BY: Aggregate data
- HAVING: Filter grouped results
SQL example
Practical SQL code
-- Select all users
SELECT * FROM users;
-- Select specific columns with condition
SELECT name, email FROM users WHERE age > 21;
-- Update a record
UPDATE users SET email = 'newemail@example.com' WHERE id = 1;
-- Delete a record
DELETE FROM users WHERE id = 2;
-- Count records
SELECT COUNT(*) FROM users;