Introduction to Structured
Query Language (SQL)
Structured Query Language (SQL) is a programming language used to manage and
manipulate data stored in relational databases. In this presentation, we’ll explore
the basics of SQL along with some advanced features.
by Ijaz Ahmad
DDL (Data Definition Language)
1 CREATE TABLE
Constructs a new table in a database
DROP TABLE 2
Removes a table and its data from a
database 3 ALTER TABLE
Modifies the structure of a table in a
TRUNCATE TABLE 4 database
Deletes all rows from a table while
keeping its structure
DML (Data Manipulation Language)
SELECT INSERT
Retrieves data from a database Adds data to a table in a database
UPDATE DELETE
Modifies data in a database Removes data from a database
Data Control Language
GRANT DENY REVOKE
Gives users permission to access Denies users permission to Removes users' permission to
and manipulate data access data access data
Primary Keys
A primary key is a column, or combination of columns, used to uniquely identify each row in a table. By default,
primary keys are used to create a clustered index.
Student ID First Name Last Name Email
101 Jane Doe jane.doe@email.com
102 John Smith john.smith@email.c
om
Joins
In SQL, a JOIN operation combines rows from two or more tables based on a related column between them.
Understanding how to use joins effectively is essential for complex queries.
Inner Join Left Join Right Join
Returns only the matching rows Returns all the matching rows Returns all the matching rows
from both tables from both tables, plus all from both tables, plus all
unmatched rows from the left unmatched rows from the right
table table
Subqueries
A subquery is a nested query that is executed within the context of another query. Subqueries can be used to
filter, sort, and aggregate data in various ways.
1 Single-Row 2 Multiple-Row 3 Inline View
Subquery Subquery Subquery
Returns only one row Returns multiple rows Returns a table that can
be used in another query
Aggregate Functions
1 SUM
Returns the sum of values in a column
2 AVG
Returns the average of values in a column
3 MIN
Returns the minimum value in a column
4 MAX
Returns the maximum value in a column