You are on page 1of 43

Chapter 7

Applications
MSc. Nguyen Khanh Loi
nkloi@hcmut.edu.vn
2/2021
MSc Nguyen Khanh Loi
Content

v MySQL
v Web development

2
MSc Nguyen Khanh Loi
IoT System Architecture

3
MSc Nguyen Khanh Loi
NoSQL vs SQL

4
MSc Nguyen Khanh Loi
SQL and NoSQL Databases

Popular relational (SQL) databases include:


• IBM DB2
• Oracle Database
• Microsoft SQL Server
• MySQL

Popular non-relational (NoSQL) databases include:


• Apache Cassandra
• Apache HBase
• MongoDB
• Redis
• ScyllaDB

5
MSc Nguyen Khanh Loi
MySQL

What is MySQL?

§ MySQL is a relational database management system


§ MySQL is open-source
§ MySQL is free
§ MySQL is ideal for both small and large applications
§ MySQL is very fast, reliable, scalable, and easy to use
§ MySQL is cross-platform
§ MySQL is compliant with the ANSI SQL standard
§ MySQL was first released in 1995
§ MySQL is developed, distributed, and supported by Oracle Corporation

6
MSc Nguyen Khanh Loi
MySQL

Who Uses MySQL?

§ Huge websites like Facebook, Twitter, Airbnb, Booking.com, Uber,


GitHub, YouTube, etc.
§ Content Management Systems like WordPress, Drupal, Joomla!,
Contao, etc.
§ A very large number of web developers around the world

7
MSc Nguyen Khanh Loi
MySQL

The Most Important SQL Commands

§ CREATE DATABASE - creates a new database


§ ALTER DATABASE - modifies a database
§ CREATE TABLE - creates a new table
§ ALTER TABLE - modifies a table
§ DROP TABLE - deletes a table
§ SELECT - extracts data from a database
§ UPDATE - updates data in a database
§ DELETE - deletes data from a database
§ INSERT INTO - inserts new data into a database

8
MSc Nguyen Khanh Loi
MySQL SELECT Statement

The SELECT statement is used to select data from a database.


The data returned is stored in a result table, called the result-set.
SELECT Syntax

SELECT column1, column2, ...


FROM table_name;

Here, column1, column2, ... are the field names of the table you
want to select data from. If you want to select all the fields
available in the table, use the following syntax:

SELECT * FROM table_name;

9
MSc Nguyen Khanh Loi
MySQL SELECT Statement

The following SQL statement selects the "CustomerName", "City", and


"Country" columns from the "Customers" table:

SELECT CustomerName, City, Country FROM Customers;

10
MSc Nguyen Khanh Loi
MySQL WHERE Clause

The WHERE clause is used to filter records.


It is used to extract only those records that fulfill a specified
condition.

WHERE Syntax

SELECT column1, column2, ...


FROM table_name
WHERE condition;

11
MSc Nguyen Khanh Loi
MySQL WHERE Clause

The following SQL statement selects all the customers from "Mexico":

SELECT * FROM Customers


WHERE Country = 'Mexico';

12
MSc Nguyen Khanh Loi
MySQL WHERE Clause

13
MSc Nguyen Khanh Loi
MySQL AND, OR and NOT Operators
The WHERE clause can be combined with AND, OR, and NOT operators.
The AND and OR operators are used to filter records based on more than one condition:
§ The AND operator displays a record if all the conditions separated by AND are TRUE.
§ The OR operator displays a record if any of the conditions separated by OR is TRUE.
§ The NOT operator displays a record if the condition(s) is NOT TRUE.

AND Syntax
SELECT column1, column2, ...
FROM table_name
WHERE condition1 AND condition2 AND condition3 ...;

OR Syntax
SELECT column1, column2, ...
FROM table_name
WHERE condition1 OR condition2 OR condition3 ...;

NOT Syntax
SELECT column1, column2, ...
FROM table_name
WHERE NOT condition;

14
MSc Nguyen Khanh Loi
MySQL ORDER BY Keyword

The ORDER BY keyword is used to sort the result-set in ascending or


descending order.
The ORDER BY keyword sorts the records in ascending order by
default. To sort the records in descending order, use
the DESC keyword.

ORDER BY Syntax
SELECT column1, column2, ...
FROM table_name
ORDER BY column1, column2, ... ASC|DESC;

15
MSc Nguyen Khanh Loi
MySQL ORDER BY Keyword

The following SQL statement selects all customers from the


"Customers" table, sorted by the "Country" column:

SELECT * FROM Customers


ORDER BY Country;

16
MSc Nguyen Khanh Loi
MySQL INSERT INTO Statement

The INSERT INTO statement is used to insert new records in a table.


INSERT INTO Syntax
It is possible to write the INSERT INTO statement in two ways:
1. Specify both the column names and the values to be inserted:
INSERT INTO table_name (column1, column2, column3, ...)
VALUES (value1, value2, value3, ...);

2. If you are adding values for all the columns of the table, you do not need to
specify the column names in the SQL query. However, make sure the order of
the values is in the same order as the columns in the table. Here, the INSERT
INTO syntax would be as follows:
INSERT INTO table_name
VALUES (value1, value2, value3, ...);

17
MSc Nguyen Khanh Loi
MySQL INSERT INTO Statement

The following SQL statement inserts a new record in the "Customers" table:
INSERT INTO Customers (CustomerName, ContactName, Address, City, PostalCode, Country)
VALUES ('Cardinal', 'Tom B. Erichsen', 'Skagen 21', 'Stavanger', '4006', 'Norway');

18
MSc Nguyen Khanh Loi
MySQL UPDATE Statement

The UPDATE statement is used to modify the existing records in a table.


UPDATE Syntax

UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;

UPDATE Customers
SET ContactName = 'Alfred Schmidt', City = 'Frankfurt'
WHERE CustomerID = 1;

19
MSc Nguyen Khanh Loi
MySQL DELETE Statement

The DELETE statement is used to delete existing records in a table.


DELETE Syntax
DELETE FROM table_name WHERE condition;

DELETE FROM Customers WHERE CustomerName='Alfreds Futterkiste';

20
MSc Nguyen Khanh Loi
MySQL INNER JOIN Keyword

INNER JOIN Syntax

SELECT column_name(s)
FROM table1
INNER JOIN table2
ON table1.column_name = table2.column_name;

21
MSc Nguyen Khanh Loi
MySQL INNER JOIN Keyword

SELECT Orders.*
FROM Orders
INNER JOIN Customers ON Orders.CustomerID = Customers.CustomerID;

22
MSc Nguyen Khanh Loi
MySQL INNER JOIN Keyword

LEFT JOIN Syntax

SELECT column_name(s)
FROM table1
LEFT JOIN table2
ON table1.column_name = table2.column_name;

23
MSc Nguyen Khanh Loi
MySQL RIGHT JOIN Keyword

RIGHT JOIN Syntax

SELECT column_name(s)
FROM table1
RIGHT JOIN table2
ON table1.column_name = table2.column_name;

24
MSc Nguyen Khanh Loi
MySQL CROSS JOIN Keyword

CROSS JOIN Syntax

SELECT column_name(s)
FROM table1
CROSS JOIN table2;

25
MSc Nguyen Khanh Loi
Practice

https://www.w3schools.com/MySQL/trymysql.asp?filename=trysql_select_columns

26
MSc Nguyen Khanh Loi
Tool

27
MSc Nguyen Khanh Loi
Web development

28
MSc Nguyen Khanh Loi
Web development

29
MSc Nguyen Khanh Loi
Web development

30
MSc Nguyen Khanh Loi
Web development

31
MSc Nguyen Khanh Loi
Web development

32
MSc Nguyen Khanh Loi
Laravel - PHP

33
MSc Nguyen Khanh Loi
MVC Model

34
MSc Nguyen Khanh Loi
Laravel - PHP

https://laravel.com/docs/10.x/installation
Creating A Laravel Project
Your local machine has PHP and Composer installed.
composer create-project laravel/laravel example-app
Start Laravel's local development server using Laravel Artisan's serve
command:
cd example-app
php artisan serve
http://localhost:8000

35
MSc Nguyen Khanh Loi
Laravel - PHP

36
MSc Nguyen Khanh Loi
Laravel - Model

php artisan make:model Car --migration

37
MSc Nguyen Khanh Loi
Laravel - Model

php artisan migrate

38
MSc Nguyen Khanh Loi
Laravel - Controller

php artisan make:controller CarController --resource

39
MSc Nguyen Khanh Loi
Laravel - Controller

40
MSc Nguyen Khanh Loi
Laravel - Routing
routes/web.php

41
MSc Nguyen Khanh Loi
Laravel - View
resources/views/cars/show.blade.php

42
MSc Nguyen Khanh Loi
Laravel - View
http://127.0.0.1:8000/cars/1

43
MSc Nguyen Khanh Loi

You might also like