...
SQL (Structured Query Language) is a standard language for managing and interacting with relational databases.
✅ Used to create, read, update, and delete (CRUD) data
✅ Works with MySQL, PostgreSQL, SQLite, Oracle, SQL Server
✅ Used in data analysis, backend dev, BI, and system design
Table: A collection of data arranged in rows and columns (like Excel)
Row: A single record
Column: A field or attribute
Primary Key: Uniquely identifies each row
Foreign Key: Links to another table’s primary key
Example Table: Students
Create a table called students:
CREATE TABLE students (
id INT PRIMARY KEY,
name VARCHAR(50),
age INT,
major VARCHAR(50)
);
Insert one record into the students table:
INSERT INTO students (id, name, age, major)
VALUES (1, 'Christian', 21, 'IT');
Insert multiple records:
INSERT INTO students (id, name, age, major)
VALUES
(2, 'Maya', 22, 'Business'),
(3, 'Abel', 23, 'Engineering');
Select all data:
SELECT * FROM students;
Select specific columns:
SELECT name, major FROM students;
Use WHERE to filter:
SELECT * FROM students
WHERE major = 'IT';
Update a student's major:
UPDATE students
SET major = 'Computer Science'
WHERE id = 1;
Delete a student:
DELETE FROM students
WHERE name = 'Maya';
Numeric comparison:
SELECT * FROM students
WHERE age > 21;
Logical operators:
SELECT * FROM students
WHERE major = 'IT' AND age > 20;
Order by age ascending:
pgsql
CopyEdit
SELECT * FROM students
ORDER BY age ASC;
Limit to top 2:
SELECT * FROM students
LIMIT 2;
Suppose you have a courses table:
Join students and courses:
SELECT students.name, courses.course_name
FROM students
JOIN courses
ON students.id = courses.student_id;
Get total students per major:
SELECT major, COUNT(*) AS total
FROM students
GROUP BY major;
Average age:
SELECT AVG(age) FROM students;
✅ Always use parameterized queries to avoid SQL injection
✅ Use foreign keys for data integrity
✅ Backup databases regularly
✅ Use indexes to improve search speed on large datasets
✅ Backend Developer
✅ Database Administrator
✅ Data Analyst
✅ Business Intelligence Engineer
✅ Full Stack Developer
✅ Backend Developer
✅ Database Administrator
✅ Data Analyst
✅ Business Intelligence Engineer
✅ Full Stack Developer