... ArdiLand Institute of Technology SQL (Structured Query Language) – Full Beginner Guide | Ardiland Institute of Technology
540-440-1540‬
USD ($)
$
United States Dollar
Br
Ethiopian Birr

SQL (Structured Query Language) – Full Beginner Guide

Created by Adugna Asrat in Quick Notes 27 Mar 2025
Share

📌 What is SQL?

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


🧱 1. Basic Terminology

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

id

name

age

major

1

Christian

21

IT

2

Maya

22

Business


📐 2. Creating Tables

Create a table called students:

CREATE TABLE students (

  id INT PRIMARY KEY,

  name VARCHAR(50),

  age INT,

  major VARCHAR(50)

);


➕ 3. Inserting Data

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');


📊 4. Selecting and Filtering Data

Select all data:

SELECT * FROM students;

Select specific columns:

SELECT name, major FROM students;

Use WHERE to filter:

SELECT * FROM students

WHERE major = 'IT';


🔁 5. Updating and Deleting Data

Update a student's major:

UPDATE students

SET major = 'Computer Science'

WHERE id = 1;

Delete a student:

DELETE FROM students

WHERE name = 'Maya';


🧮 6. Using Operators

Numeric comparison:

SELECT * FROM students

WHERE age > 21;

Logical operators:

SELECT * FROM students

WHERE major = 'IT' AND age > 20;


🧩 7. Sorting and Limiting Results

Order by age ascending:

pgsql

CopyEdit

SELECT * FROM students

ORDER BY age ASC;

Limit to top 2:

SELECT * FROM students

LIMIT 2;


🔗 8. Joins (Relating Multiple Tables)

Suppose you have a courses table:

course_id

course_name

student_id

101

Databases

1

102

Web Development

3

Join students and courses:

SELECT students.name, courses.course_name

FROM students

JOIN courses

ON students.id = courses.student_id;


📊 9. Aggregation and Grouping

Get total students per major:

SELECT major, COUNT(*) AS total

FROM students

GROUP BY major;

Average age:

SELECT AVG(age) FROM students;


🔒 10. Security and Best Practices

✅ 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


💼 Career Uses of SQL

✅ Backend Developer
✅ Database Administrator
✅ Data Analyst
✅ Business Intelligence Engineer
✅ Full Stack Developer

💼 Career Uses of SQL

✅ Backend Developer
✅ Database Administrator
✅ Data Analyst
✅ Business Intelligence Engineer
✅ Full Stack Developer

Comments (0)

Share

Share this post with others