Introduction of
Structured Query
Language (SQL)
2
Learning Outline
Mastery of basic S QL S tructuring and defining entities and
01 commands such as S E LE CT,
WHE R E GR OUP BY and J OIN.
04 attributes for effective database
management.
Application of S QL clauses to R ecognizing the role of primary
02 filter, group, and retrieve data
effectively.
05 keys as unique identifiers of
records.
Problem-solving using S QL in R ecognizing the role of primary
03 real-world scenarios.
06 keys as unique identifiers of
records.
S QL S yntax and
S tructure
4
What is S QL ?
Title
Introduction To SQL Syntax and Structure
• SQL (Structured Query Language) is the standard
language for interacting with relational databases.
• Some of the basic commands are S EL ECT,
INSE R T, CRE ATE , and JOIN
• SQL is widely use in industries like healthcare,
finance, e-commerce and technology for data
analysis and management.
SQL Commands
These are basically categorized into five categories mainly:
DDL DQL DML DCL TCL
Data Definition Data Query Data Manipulation Data Control Transactional Control
Language Language Language Language Language
• CRE ATE • INSE R T • GRANT • COMMIT • SE LE CT
• DROP • UPDATE • RE VOKE • ROLLBACK
• ALTE R • DELE TE • SAVE POINT
• TRUNCATE
SQL Commands
DDL DCL
This consists of SQL commands that This consists of SQL commands that
can be used to define the database mainly deal with the rights,
schema permissions, and other controls of the
database system.
DML DQL
It is the component of the SQL statement It is used for performing queries
that controls access to data and the on the data within schema.
database.
TCL
This consists of SQL commands that are
used to control the execution of a
transaction.
SQL Commands
SQL
Commands
DDL DQL DCL TCL DML
CRE ATE INSE R T COMMIT SE LE CT GRANT
DROP UPDATE SAVE POIN RE VOKE
T
ALTE R DELE TE ROLLBACK
SELECT Statement
The select statement retrieves data from one or more tables in a
database.
Employee_id First_name Last_name Department Salary
101John Mathew IT 50000
102Chidinma Oga HR 45000
103Shola Abiola Finance 55000
104Joseph Pam IT 60000
105David Clark HR 48000
SELECT Statement
Syntax:
SE LE CT Column1, Column2, ...
FROM table_name;
Example
SE LE CT First_name, Last_name
FROM Employees;
WHERE Statement
The where clause filters database on a specific
conditions
Syntax:
SE LE CT column1
FROM table_name
WHER E condition;
Example
SE LE CT *
FROM employees
WHER E department = “IT”
WHERE CLAUSE
GROUP BY Statement
The GROUP BY clause groups rows that
have the same values in a specified
columns and is used with aggregate
functions like SUM, COUNT, AVG.
Syntax:
SE LE CT column1,
aggregate_function(column2)
FROM table_name
GR OUP BY column1
Example
SE LE CT department_id, COUNT(*) AS
total_employees
FROM employees
GR OUP BY department_id
JOIN Statement
Combines rows from two or more tables based on
related columns.
Syntax:
SE LE CT columns
FROM table1
JOIN table2
ON table1.column_name = table2.column_name;
Example
SE LE CT e.first_name, e.last_name,
d.department_name
FROM employees e
JOIN departments d
ON e.department_id = d.id;
Industry Application
Problem:
As a newly recruited data analyst, your HR department requests the following insights:
Total salaries paid Departments with Employee names along
per department. employees earning with their respective
above ₦290,000 department's salary
payments.
Database Design
Basics
16
Why is Database Design Important?
Minimizes Redundancy:
Avoids duplicate data. Ensures Data Integrity:
Data remains accurate
and reliable.
Database
Design
Simplifies Maintenance:
Easier to update, expand,
or troubleshoot.
Improves Performance:
Optimized data retrieval
and storage.
Key Concepts in Database Design
Entities
They can be defined as fundamental building blocks that help us structure
information in a way that is logical and meaningful.
Attributes
An attribute is a specific piece of information about that object.
Relationship
A relationship is a connection or association between two or more entities that
expresses how they interact or depend on each other.
Key Concepts in Database Design
In an Entity Relationship (ER ) diagram, entities are represented by rectangles and
attributes by ovals, and the lines between them show how the entities are related to each
other.
One-to-One
01
Relationships
One-to-Many
Types of
02 Relationships
Relationships
Many-to-Many
03 Relationships
Key Concepts in Database Design
One-to-one relationship
occurs when one record in a table is related to only one record in another table.
Student 1 has 1 ID card
Key Concepts in Database Design
One-to-many relationship
occurs when one record in a table is related to multiple records in another table
1 M
Student Register Courses
Key Concepts in Database Design
Many-to-many relationship
occurs when record in a table is related to multiple records in another table.
M M
Orders Multiples Customers
Primary Key
A unique identifier for a table's records.
Example
CRE ATE TABLE employees (
id INT AUTO_INCRE MENT PR IMARY KEY,
first_name VARCHAR (50),
last_name VARCHAR (50)
);
Here, id is the primary key.
Foreign Key
Links two tables together.
Example
CRE ATE TABLE departments (
id INT AUTO_INCR E MENT PR IMARY KEY,
department_name VARCHAR (50)
);
CRE ATE TABLE employees (
id INT AUTO_INCR E MENT PR IMARY KEY,
first_name VARCHAR (50),
last_name VARCHAR (50),
department_id INT,
FORE IGN KEY (department_id) RE FE R E NCE S departments(id)
);
This links employees.department_id to departments.id.
Conclusion
At the end learners:
Acquire training Interact with Join tables to
on basic SQL relational derive insights Make a big
commands and database using impact with
database design SQL commands and solve real-
professional
basics. like SE LE CT, world problems. slides, charts,
WHE R E GR OUP infographics
BY and JOIN. and
01 02 03 04
Assignments
You’re working as a healthcare analyst. The healthcare management system stores data
about patients, doctors and appointments in the following database tables. (find the tables
here)
Write a query to find all the patients in the state “Fct Abuja”, ”Plateau”.
Retrieve the total number of male and female patients.
Write a query to list doctors and their specialties in state where confirmed
appointments exist.