LPA SQL for Beginners Learn SQL Using MySQL and Database Design SEP2024
LPA SQL for Beginners Learn SQL Using MySQL and Database Design SEP2024
If you have any questions of queries, please add your feedback in the Q&A section of the course on Udemy.
Best regards,
Tim Buchalka
Learn Programming Academy
IT Systems Engineer
COURSE INTRODUCTION
SQL-0020-1
COURSE INTRODUCTION
No Prior Knowledge
Exper
Beginner
t
You know the basics of SQL and want to take your skills to the
next level
COURSE INTRODUCTION
SQL-0040-1
Section 2
Learn about Databases, SQL and MySQL
Normalization
Relationships
Constraints
Non-Correlated Subqueries
Correlated Subqueries
What SQL and MySQL are and how they are related.
INTRODUCTION TO DATABASES
SQL-0080-1
WHAT IS A DATABASE
An organised collection of information (data).
SQL SQL
SQL SQL
SELECT * FROM
customers;
RDBMS
MySQL
PostgreSQL
SQL Server
Oracle
INTRODUCTION TO DATABASES
SQL-0090-1
WHAT IS AN RDBMS
A relational database is a collection of data organised into
tables.
CREATING TABLES
MODIFYING TABLES
DELETING TABLES
PRODUCTS
CUSTOMERS
ORDERS
When we create our tables we will learn how to define our primary keys.
Can’t be the first_name, last_name or even telephone number as they are not unique.
•A foreign key is a column whose values match the values of another tables primary key
column.
• The table with the primary key is called the reference, or parent, table and the table with
the foreign key is called the child table.
Customer_id column and product_id column are FOREIGN KEYS in the orders table.
They are referencing PRIMARY KEY columns in the customers and products tables.
CUSTOMERS
ID FIRST_NAME LAST_NAME GENDER PHONE_NUMBER
•Add a foreign key to the owner_id field in the pets table referencing the id
field in the people table.
PRODUCTS
ID NAME PRICE COFFEE_ORIGIN
1 ESPRESSO 2.50 BRAZIL
2 MACCHIATO 3.00 BRAZIL
3 CAPPUCCINO 3.50 COSTA RICA
4 LATTE 3.50 INDONESIA
5 AMERICANO 3.00 BRAZIL
6 FLAT WHITE 3.50 INDONESIA
7 FILTER 3.00 INDIA
2. From the products table, select the name for all products that have a price greater than
3.00 or a coffee origin of Sri Lanka.
3. How many male customers don’t have a phone number entered into the customers
table?
2. From the orders table, select all the orders from February 2017 for customers with id’s
of 2, 4, 6 or 8.
3. From the customers table, select the first name and phone number of all customers
who’s last name contains the pattern ‘ar’.
2. From the orders table, select the first 3 orders placed by customer with id 1, in February
2017.
3. From the products table, select the name, price and coffee origin but rename the price
to retail_price in the results set.
How to write LEFT and RIGHT JOINs queries and the differences between them.
How to SELECT data from more than two tables using multiple JOIN statements.
Table 1 Table 2
Select product name and order time for filter coffees sold between January 15th 2017 and
February 14th 2017.
Select the product name and price and order time for all orders from females in January
2017.
DATABASE DESIGN
SQL-0940-1
Database
Design
NORMALIZATION
RELATIONSHIPS
CONSTRAINTS
DATABASE DESIGN
SQL-0960-1
WHAT IS NORMALIZATION
Normalization is the process of efficiently organizing
data in a database.
•Why?
DATABASE DESIGN
SQL-0980-1
WHAT IS 1NF
Tables are in 1NF if:
•No repeated rows of data.
DATABASE DESIGN
SQL-1000-1
WHAT IS 2NF
Tables are in 2NF if:
•They conform to 1NF.
STUDENT AGE
Natasha Williams 15
Daniel James 16
Simon Brown 14
Emma Thomas 14
DATABASE DESIGN
SQL-1020-1
WHAT IS 3NF
Tables are in 3NF if:
•They conform to 2NF.
DATABASE DESIGN
SQL-1040-1
WHAT ARE
RELATIONSHIPS
Tables are related through primary and foreign keys.
One to One Relationship.
One to Many Relationship.
Many to Many Relationship.
DATABASE DESIGN
SQL-1060-1
WHAT IS ONE TO ONE
Where a key to one table appears no more than once
as the key in another table and vice versa.
1 0..1
PRODUCTS PRODUCT_DETAILS
DATABASE DESIGN
SQL-1080-1
WHAT IS ONE TO MANY
Where a primary key of one table can be in multiple
rows of a foreign key column of another table.
1 0..m
CUSTOMERS ORDERS
DATABASE DESIGN
SQL-1100-1
WHAT IS MANY TO MANY
Where two tables can have many instances of each
other.
PRODUCTS ORDERS
1 1..m 1..m 1
ORDER_DETAILS
DATABASE DESIGN
SQL-1120-1
CONSTRAINTS
NOT NULL - A column can’t contain any null values.
Consisting of 7 tables.
AGGREGATE FUNCTIONS
SQL-1340-1
WHAT YOU WILL LEARN
What aggregate functions are.
AGGREGATE FUNCTIONS
SQL-1360-1
WHAT ARE AGGREGATE FUNCTIONS
Perform a calculations on data within a column and
returns one result row.
SUM
MIN
MAX
AVG
2. Select the film name and count the number of screenings for each
film that is over 2 hours long.
SUBQUERIES
SQL-1580-1
WHAT YOU WILL LEARN
WHAT SUBQUERIES ARE AND THE DIFFERENT TYPES.
NON-CORRELATED SUBQUERIES
CORRELATED SUBQUERIES
SUBQUERIES
SQL-1600-1
WHAT ARE SUBQUERIES
Subqueries are queries nested within other queries.
Non-correlated.
Correlated.
Inner query runs first and produces a result set, which is then
used by the outer query.
SQL FOR BEGINNERS SUBQUERIES
WHAT ARE SUBQUERIES SQL-1600-4
CORRELATED SUBQUERY
The inner query can’t run independently of the outer query.
The inner query runs for every row in the outer query.
3. Select each film name and the number of screenings for that
film.
SQL FOR BEGINNERS MYSQL FUNCTIONS - STRING FUNCTIONS AND DATE FUNCTIONS
Section Introduction SQL-1720-2
STRING FUNCTIONS
Concatenate
Substring
Upper
Lower
SQL FOR BEGINNERS MYSQL FUNCTIONS - STRING FUNCTIONS AND DATE FUNCTIONS
Section Introduction SQL-1720-3
DATE FUNCTIONS
Date
Month
Year
SQL FOR BEGINNERS MYSQL FUNCTIONS - STRING FUNCTIONS AND DATE FUNCTIONS
Section Introduction SQL-1720-4
IN THIS SECTION
Multiple exercises with video solutions.
SQL FOR BEGINNERS MYSQL FUNCTIONS - STRING FUNCTIONS AND DATE FUNCTIONS
Section Introduction SQL-1720-5
WHAT ARE MySQL FUNCTIONS?
SQL FOR BEGINNERS MYSQL FUNCTIONS - STRING FUNCTIONS AND DATE FUNCTIONS
What Are MySQL Functions? SQL-1730-1
WHAT ARE MySQL FUNCTIONS?
Functions are stored programs which can be passed parameters and return a
value.
SQL FOR BEGINNERS MYSQL FUNCTIONS - STRING FUNCTIONS AND DATE FUNCTIONS
What Are MySQL Functions? SQL-1730-2
STRING FUNCTIONS
Functions that take string parameters.
SQL FOR BEGINNERS MYSQL FUNCTIONS - STRING FUNCTIONS AND DATE FUNCTIONS
What Are MySQL Functions? SQL-1730-3
DATE FUNCTIONS
Functions that take date, time or datetime parameters.
SQL FOR BEGINNERS MYSQL FUNCTIONS - STRING FUNCTIONS AND DATE FUNCTIONS
What Are MySQL Functions? SQL-1730-4
Exercise 1
Concatenate the film names and length from the films table.
Select the customers first name in lower case and their last name in upper case for
each customer with a last name of ‘Smith’.
Select the last 3 letters of each film name from the films table.
Concatenate the first three letters in the first_name and last_name columns together
from the customers table.
SQL FOR BEGINNERS MYSQL FUNCTIONS - STRING FUNCTIONS AND DATE FUNCTIONS
Exercise 1 SQL-1800-1
Exercise 2
Select the film id and start time from the screenings table for the date of 20th of
October 2017.
Select all the data from the screenings table for the start time between the 6th and
13th of October 2017.
Select all the data from the screenings table for October 2017.
SQL FOR BEGINNERS MYSQL FUNCTIONS - STRING FUNCTIONS AND DATE FUNCTIONS
Exercise 2 SQL-1900-1
SQL for Beginners Slides
Challenge Slides.
CHALLENGES
SQL-1940-1
CHALLENGE ONE
Which films are over 2 hours long?