MySQL Fast Track Course
MySQL Fast Track Course
Course
By OLIR Learning
Christopher Jeberson
Founder & Director of Olir
IT Experience 1
13 years of experience in IT field working with
TCS
2 Clients
Microsoft
Nokia
Roles 3 Verizon
2 Supports SQL
Used in web applications, analytics, e-commerce, and more.
Read
Retrieve data from the database.
Update
Modify existing data in the database.
Delete
Remove data from the database.
Database Overview: classicmodels
Business Context: This database models a vehicle business that sells products and manages orders,
employees, customers, and payments.
Tables
LIMIT ORDER BY
The LIMIT clause restricts the The ORDER BY clause sorts the data
number of rows returned. in ascending or descending order.
SELECT Statement
Used to retrieve data from one or more tables.
Using Distinct
SELECT DISTINCT productLine FROM products;
practice
Select all columns from the customers table.
1
3 Use aliases to rename columns while selecting product names and prices.
Select all employees with their first and last names combined.
5
SQL Operations
Arithmetic Operations
Comparison Operations
Logical Operations
String Operations
Date and Time Operations
Aggregation Operations
NULL Operation
Other Operations
Arithmetic Operation
Perform mathematical calculations on numeric data.
Divide Modulus
SELECT buyPrice / 2 FROM products; SELECT buyPrice % 2 FROM products;
Comparison Operation
Used to compare values
BETWEEN IN
SELECT * FROM products SELECT * FROM products
WHERE buyPrice BETWEEN 50 AND 100; WHERE buyPrice IN (50, 100, 150);
Logical Operation
Combine conditions in a query using logical operators.
AND OR NOT
SELECT * FROM products SELECT * FROM products SELECT * FROM products
WHERE buyPrice > 50 AND WHERE buyPrice > 100 OR WHERE NOT productLine =
productLine = 'Motorcycles'; productLine = 'Classic Cars'; 'Motorcycles';
String Operation
Manipulate and work with text data.
LIKE
SELECT productName FROM products WHERE productName LIKE 'S%';
Date and Time Operations
Work with date and time data in SQL.
Add Days
SELECT orderDate + INTERVAL 10 DAY FROM orders;
Aggregate Operations
Perform calculations on multiple rows of data and return a single value.
MAX MIN
SELECT MAX(buyPrice) AS MaxPrice FROM SELECT MIN(buyPrice) AS MinPrice FROM products;
products;
NULL Operations
Functions to handle NULL values in SQL.
CAST IF
SELECT CAST(buyPrice AS DECIMAL(10,2)) FROM SELECT IF(buyPrice > 100, 'Expensive', 'Affordable')
products; AS PriceCategory FROM products;
CASE
SELECT CASE WHEN buyPrice > 100 THEN 'Expensive' ELSE 'Affordable' END AS PriceCategory FROM products;
practice
Select all products where buyPrice is greater than 100 and quantityInStock is more than 50.
3
Concatenate the contact first names and contact last names of all customers into a single column
5
called "Contact Fullname."
Calculate the number of days between orderDate and shippedDate for all orders.
6
10 Categorize Order as 'High Volume' if Ordered quantity is greater than 100, and 'Low Volume'
otherwise from orderDetails
Aggregation
The GROUP BY clause in SQL is used to group rows that have the same values
SUM
SELECT productLine, SUM(buyPrice) AS totalValue FROM products GROUP BY productLine;
Aggregation - Filtering
The HAVING clause is used to filter data after it has been grouped.
HAVING
SELECT orderNumber, COUNT(*) AS orderCount
FROM orderdetails
GROUP BY orderNumber
COMBINE
SELECT orderNumber, COUNT(*) AS orderCount
FROM orderdetails
GROUP BY orderNumber
Limit
Controls the number of rows returned by a SELECT query.
LIMIT
SELECT productName, buyPrice
FROM products
LIMIT 5;
OFFSET
SELECT productName, buyPrice
FROM products
LIMIT 5, 5;
practice
Calculate the total number of products in the Motorcycles product line.
1
Find the maximum buyPrice of all products in the Classic Cars product line.
2
Retrieve all products and sort them first by productLine in ascending order, then by buyPrice in
5
descending order.
Order By
Sorts the result set of a query by one or more columns.
FROM products
FROM products
LIMIT 5, 5;
Joins
MULTIPLE JOINS
You can join more than two tables
by chaining multiple JOIN clauses.
Each additional table is joined in the
same manner as the first two.
Join
Inner Left
SELECT orders.orderNumber, orders.orderDate, SELECT customers.customerName,
customers.customerName orders.orderNumber
ON orders.customerNumber = ON customers.customerNumber =
customers.customerNumber; orders.customerNumber;
Right Full
SELECT orders.orderNumber, SELECT customers.customerName,
customers.customerName orders.orderNumber
SELECT customers.customerName,
orders.orderNumber
FROM orders
Multiple Joins
SELECT orders.orderNumber, customers.customerName, employees.firstName, employees.lastName
FROM orders
2 Select employeeNumber and customerName for all customers handled by a specific sales
representative (use salesRepEmployeeNumber to join employees and customers).
3 Select all customers and their orderNumbers, including customers who have not placed any orders.
Retrieve a list of all employees and the offices they are assigned to, even if an employee doesn't have
4
an assigned office.
List all orders and the customers who placed them, including orders that do not have an associated
5
customer (hypothetical).
Select all offices and their associated employees, including offices that currently have no employees.
6
Retrieve all customers and orders, ensuring that customers without orders and orders without
7
customers are both included.
Update
INSERT UPDATE
Inserting new row of data Modify existing data
Insert
Used to add new rows of data into a table
Using Join
DELETE orders
FROM orders
Truncate
Delete table
TRUNCATE TABLE customers;
Drop
Table Database
DROP TABLE employees; DROP DATABASE sales_db;
Column View
ALTER TABLE productlines DROP VIEW customer_orders_view;
Index Trigger
DROP INDEX idx_customer_name ON customers; DROP TRIGGER order_after_insert;
Create
FROM students
1 Numeric 2 String
TINYINT, SMALLINT, MEDIUMINT, INT, BIGINT, CHAR, VARCHAR, TEXT, MEDIUMTEXT, LONGTEXT
DECIMAL, FLOAT, DOUBLE
3 Datetime 4 BINARY
DATE, TIME, DATETIME, TIMESTAMP BLOB, MEDIUMBLOB, LONGBLOB
5 Other
BOOLEAN
TABLE CREATION
CREATE TABLE students (
studentID INT,
name VARCHAR(100),
age INT
);
Constraints
5 CHECK
Ensures that all values in a column satisfy a specific condition.
lastName VARCHAR(50)
);
studentID INT,
courseID INT,
);
Cascading
Actions to be taken when a referenced row in the parent table is updated or deleted.
firstName VARCHAR(50),
lastName VARCHAR(50)
);
departmentName VARCHAR(100),
employeeID INT,
ON DELETE CASCADE
ON UPDATE CASCADE
);
Thank You
Thank you for attending this MySQL Fast Track Course. I hope you enjoyed the sessions and learned valuable skills.
Feel free to reach out if you have any questions or require further assistance. I am happy to support you on your
MySQL journey.
Email: christopher@olirlearning.com