Your SQL Quickstart Guide
Your SQL Quickstart Guide
MADSON
KEY ANALYST
SKILLS
TABLE OF
CONTENTS
ANDREW
MADSON
INTRODUCTION
WHAT IS A DATA BASE?
HOW IS IT ORGANIZED?
WHAT IS SQL?
WHAT ARE THE
DIFFERENT SQL
DATABASES?
ANDREW
MADSON
WHAT IS A
DATABASE?
A database is an organized
collection of data that is stored and
accessed electronically. Databases
are designed to hold structured data
or data that can be stored in tables
with rows and columns. They
provide a way to manage large
amounts of data efficiently and
allow for complex operations and
queries to be performed on the data.
ANDREW
MADSON
DATABASE
COMPONENTS
A collection of database objects, including tables, views,
SCHEMA indexes, and procedures.
ANDREW
MADSON
HOW IS IT
ORGANIZED?
TABLE
PRIMARY
KEY
FOREIGN
KEY
SCHEMA
ANDREW
MADSON
WHAT IS A
TABLE?
SOURCE: https://www.w3resource.com/sql/sql-basic/the-components-of-a-table.php
ANDREW
MADSON
WHAT IS SQL?
SQL (Structured Query Language) is
a programming language used to
manage and manipulate relational
databases. SQL is primarily used for
managing data held in a relational
database management system
(RDBMS) or for processing data in a
stream management system. It is
particularly effective for handling
structured data, i.e., data
incorporating relations among
entities and variables.
ANDREW
MADSON
WHAT ARE THE TYPES
OF SQL DATABASES?
This is an open-source relational database management system (RDBMS)
owned by Oracle. It's widely used in web applications and is a component
MySQL of the LAMP web application software stack (Linux, Apache, MySQL,
Perl/PHP/Python).
An RDBMS from IBM, DB2 supports the relational model, but also supports
IBM DB2 object-relational features and non-relational structures like JSON and XML.
ANDREW
MADSON
SQL BASICS
SQL SYNTAX
SELECT - FROM - WHERE
GROUP BY - HAVING
ORDER BY
AGGREGATE
FUNCTIONS
ANDREW
MADSON
SELECT - FROM -
WHERE
This command is used to select data from a
database. The data returned is stored in a
result table, called the result-set. You
SELECT specify the columns you want after the
SELECT keyword. If you want to select all
columns, you can use *.
ANDREW
MADSON
EXAMPLE: SELECT -
FROM - WHERE
n this example, the SELECT command is
SELECT used to specify that we want the FirstName
and LastName columns.
ANDREW
MADSON
GROUP BY - HAVING
ANDREW
MADSON
EXAMPLE: GROUP BY
In this example, the SELECT statement is
combined with GROUP BY to group the
employees based on their Department and
SELECT then count the number of EmployeeID in each
department. The COUNT(EmployeeID)
function will return the number of employees
in each department.
ANDREW
MADSON
ORDER BY
The ORDER BY keyword in SQL is
used to sort the result-set in
ORDER BY ascending or descending order.
It sorts the records in a result
set by one or more columns.
ANDREW
MADSON
EXAMPLE: ORDER BY
In this example, the SELECT statement is used
to specify that we want the FirstName,
SELECT LastName, and Salary columns from the
Employees table.
ORDER
results by the Salary column in descending
order (DESC). So the statement will return a
table of first names, last names, and salaries of
BY employees, ordered from the highest salary to
the lowest.
ANDREW
MADSON
AGGREGATE
FUNCTIONS
This function returns the
COUNT number of rows that matches a
specified criterion.
ANDREW
MADSON
EXAMPLE:
AGGREGATE
FUNCTIONS
ANDREW
MADSON
EXAMPLE: COUNT
TotalEmployees
OUTPUT 7
ANDREW
MADSON
EXAMPLE: AVG
AverageSalary
OUTPUT 77142.86
ANDREW
MADSON
EXAMPLE: MIN
LowestSalary
OUTPUT 70000
ANDREW
MADSON
EXAMPLE: MAX
HighestSalary
OUTPUT 90000
ANDREW
MADSON
EXAMPLE: SUM
TotalSalary
OUTPUT 540000
ANDREW
MADSON
JOINS
This returns records that have
INNER matching values in both tables.
ANDREW
MADSON
EXAMPLE: JOINS
TABLE A 'EMPLOYEES'
EmployeeID FirstName LastName
1 John Doe
2 Jane Smith
3 Mary Johnson
TABLE B 'DEPARTMENTS'
1 HR 1
2 IT 2
3 Marketing 4
ANDREW
MADSON
EXAMPLE: INNER
TABLE A 'EMPLOYEES' TABLE B 'DEPARTMENTS'
EmployeeID FirstName LastName DeptID DeptName EmployeeID
1 John Doe 1 HR 1
2 Jane Smith 2 IT 2
OUTPUT
John Doe HR
Jane Smith IT
ANDREW
MADSON
EXAMPLE: LEFT
TABLE A 'EMPLOYEES' TABLE B 'DEPARTMENTS'
EmployeeID FirstName LastName DeptID DeptName EmployeeID
1 John Doe 1 HR 1
2 Jane Smith 2 IT 2
OUTPUT
FirstName LastName DeptName
John Doe HR
Jane Smith IT
ANDREW
MADSON
EXAMPLE: RIGHT
TABLE A 'EMPLOYEES' TABLE B 'DEPARTMENTS'
EmployeeID FirstName LastName DeptID DeptName EmployeeID
1 John Doe 1 HR 1
2 Jane Smith 2 IT 2
OUTPUT
FirstName LastName DeptName
John Doe HR
Jane Smith IT
ANDREW
MADSON
EXAMPLE: FULL
TABLE A 'EMPLOYEES' TABLE B 'DEPARTMENTS'
EmployeeID FirstName LastName DeptID DeptName EmployeeID
1 John Doe 1 HR 1
2 Jane Smith 2 IT 2
OUTPUT
John Doe HR
Jane Smith IT
ANDREW
MADSON
RESOURCES
SQL: A Practical Introduction for
Querying Databases
ANDREW
MADSON
HOORAY!
🥳
Save this post, and tag me
as you develop these data
analytics core skills.
HAPPY LEARNING!
🙌
ANDREW
MADSON