Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 14

SQL for Data Analysis

Lesson 2
SQL Basics
Overview
• Course overview
• The 3 W’s of SQL
• Intro to databases and ERDs
• SQL statements
• Basic SQL commands:
• SELECT
• FROM
• WHERE
• LIMIT
• Resources
Course Overview
Data
Cleaning
Temporary
tables
Subqueries
Aggregations
JOINs
Basic SQL
The 3 W’s of SQL
• What is SQL
• Structured Query Language
• Used for working with databases
• Who uses SQL
• Any data related professional will need SQL to extract, manipulate, and define data
• Data engineers, data analyst, data scientist, database admin, etc
• Why SQL is popular
• SQL is the foundation for dealing with data stored in database
• So much data out there these days
• Easy to learn, very efficient
Intro to databases and ERD
What is a database?
• A set of raw data in tables as columns and rows
What is ERD?
• Entity Relationship Diagram
• Visual layout of the different entities in regards to the data
• ERDs are used to give the analyst an idea of how the database looks like in terms of:
• The names of the tables
• The columns in each table
• The way the tables work together
Example of ERD
SQL Statements
• The key to SQL is understanding statements. A few statements include:
1. CREATE TABLE is a statement that creates a new table in a database.
2. DROP TABLE is a statement that removes a table in a database.
3. UPDATE allows you to change data in a table.
4. INSERT INTO allows you to add a row to a table.
5. SELECT allows you to read data and display it. This is called a query.
Basic SQL Commands
• A SELECT statement must have these keywords in the following order:
SELECT name, [column name(s)]
FROM [table name(s)]
WHERE [condition]
LIMIT [number]
Formatting best practices
• Write keywords in UPPER CASE
• Avoid spaces in table and variable names
• Use white space in queries – enter between clauses
Using Operators in the WHERE clause
• Arithmetic operators (used with numeric values)
• Logical operators (used with text)
• IN
• LIKE
• NOT
• BETWEEN
• AND
• OR
Arithmetic Operators
Operator Description
= Equal

<> != Not equal

> Greater than

< Less than

>= Greater than or equal

>= Less than or equal


Logical operators
Operator Description
Combine operations where all combined
AND conditions must be true
Combine operations where at least one of the
OR combined conditions must be true
IN Specifies multiple possible values for a column
NOT Not having a certain condition
LIKE Search for a pattern
BETWEEN Between an inclusive range
Words of the Day
• SQL
• Statement
• Database
• Entity Relationship Diagram (ERD)
Resources
• https://www.udacity.com/course/sql-for-data-analysis--ud198
• https://mode.com/sql-tutorial/
• https://mode.com/sql-tutorial/sql-business-analytics-training/
• https://drive.google.com/drive/folders/15HCCaqipeW8MgAtdF2tXzRY1
CY0fm-U2?usp=sharing

You might also like