0% found this document useful (0 votes)
36 views

Build and Accesing MySQL Database Using XAMPP

This document discusses building and accessing a MySQL database using XAMPP. It begins with an introduction to MySQL and how it is a relational database management system based on SQL queries. It then discusses how XAMPP can be used to test MySQL, PHP, Apache and Perl projects locally before moving them to a live server. The document provides some SQL queries and examples to demonstrate interacting with database tables for customers and products. It also includes a section on connecting to the MySQL database.

Uploaded by

adyatma ardi
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views

Build and Accesing MySQL Database Using XAMPP

This document discusses building and accessing a MySQL database using XAMPP. It begins with an introduction to MySQL and how it is a relational database management system based on SQL queries. It then discusses how XAMPP can be used to test MySQL, PHP, Apache and Perl projects locally before moving them to a live server. The document provides some SQL queries and examples to demonstrate interacting with database tables for customers and products. It also includes a section on connecting to the MySQL database.

Uploaded by

adyatma ardi
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 26

BUILD AND ACCESING MYSQL DATABASE

USING XAMPP
Achmad Adyatma Ardi1
Programmer, Data Scientist, Engineer
*Corresponding author : [email protected]
Saturday, June 4, 2022

Abstract

Data science is a discipline where we try to answer questions that is needed instead of
using a mere assumption, we use data and logical thinking to answer that question
with a belief. In a business purposes, even though the value of uncertainty is always
there, it would be wise to make decisions based on the data you have. Data can be
your best friend in making important decisions. On this occasion, I will try to analyze
the data with the aim of answering important business-related questions using the
Python programming language with Pandas and Matplotlib libraries. Hope you enjoy
it!

Keyword : data science, python programming, sales analysis, python pandas, python
matplotlib, answer questions

Table of contents :
Ch. 1 Introduction....................................1
Ch. 2 Introduction....................................2
Additional attachment :
Attachment. 1 SQL Queries and Examples3
Attachment. 2..........................................4
Attachment. 3..........................................4
Attachment. 4..........................................4
currently enjoying widespread,
effective use regardless of industry,
Ch. 1 Introduction it’s clear that anyone involved with
enterprise data or general IT should at
MySQL is one of the most least aim for a basic familiarity of
recognizable technologies in the MySQL.
modern big data ecosystem. Often With MySQL, even those new to
called the most popular database and relational systems can immediately

1 | Achmad Adyatma Ardi


build fast, powerful, and secure data world of other popular query
storage systems. MySQL’s languages and structured data stores.
programmatic syntax and interfaces
are also perfect gateways into the wide
I. 1 What is MySQL ?

completely free to use. Experienced


MySQL is a relational database developers can even dive right in
management system (RDBMS) and change its source code to suit
based on the SQL (Structured their needs, if they wish. Even
Query Language) queries. It is one though MySQL is free to use,
of the most popular languages for Oracle does offer premier support
accessing and managing the records services which you can buy through
in the table. MySQL is open – a commercial license
source and free software under the
GNU license. Oracle company
I. 3 XAMPP
supports it.
XAMPP is a cross – platform
I. 2 SQL vs. MySQL : What’s the web server that is free and open –
difference ? source. XAMPP is a short form for
Cross – Platform (X), Apache (A),
SQL and MySQL are two of the MySQL (M), PHP (P), and Perl (P).
most popular data management XAMPP is a popular cross –
tools in the world. But for a platform web server that allows
beginner, or even someone with programmers to write and test their
more experience, the difference code on a local webserver. It was
between the two can be confusing. created by Apache Friends, and the
SQL stands for Structured Query public can revise or modify its
Language and is pronounced native source code. It includes
“S.Q.L” or “Sequel”. It is a special MariaDB, Apache HTTP server,
kind of programming language that and interpreters for PHP and Perl.
is used for communicating with a Simply needed for a XAMPP are :
database. If you want to add, 1. XAMPP is simply a local host
retrieve, or update data in a or server
database you can use SQL to do 2. This local server runs on your
that. personal computer, whether
MySQL is an open source it’s a desktop or a laptop
Relational Database Management 3. It is used to test clients or
System (RDBMS) owned by websites before publishing
Oracle. It is an extremely popular them to a remote web server
tool for several reasons. Firstly, its 4. On a local computer, the
open source status, it means XAMPP server provides a

2 | Achmad Adyatma Ardi


suitable environment for
testing MySQL, PHP,
Apache, and Perl projects.
Because most real – world
web server deployments share
the same components as
XAMPP, moving from a local
test server to a live server is
straightforward

Ch. 2 How to connect

https://www.rose-hulman.edu/
class/csse/csse290-
WebProgramming/201520/
SupportCode/SQL-setup.html

References

https://pynative.com/python-mysql-
database-connection/

https://www.educba.com/what-is-
xampp/

3 | Achmad Adyatma Ardi


Attachment. 1 SQL Queries and Examples

Additional Attachment
SQL Queries and Examples
Db : Customers
CustomerID CustomerName ContactName Address City PostalCode Country
1 Alfreds Futterkiste Alfred Schmidt Obere Str. 57 Frankurt 12209 Germany
Ana Trujillo Avda. de la
2 Ana Trujillo México D.F. 05021 Mexico
Emparedados y helados Constitución 2222
Antonio Moreno
3 Antonio Moreno Mataderos 2312 México D.F. 05023 Mexico
Taquería
4 Around the Horn Thomas Hardy 120 Hanover Sq. London WA1 1DP UK
(new record) 5 Achmad Adyatma Ardi Achmad Taman ubud Tangerang 15810 Indonesia
(new record) 6 Laiba nafisah null null Tangerang null Indonesia
(update rec) 7 Laiba nafisah Laiba null Bogor null Indonesia
Ana Trujillo Avda. de la
(update 8 Humaira México D.F. 05021 Mexico
Emparedados y helados Constitución 2222
multiple
Antonio Moreno
records) 9 Humaira Mataderos 2312 México D.F. 05023 Mexico
Taquería

Db : Products
ProductID ProductName SupplierID CategoryID Quantity Unit Price
1 Chais 1 1 2 10 boxes x 20 bags 18
2 Chang 1 1 4 24 - 12 oz bottles 19
3 Aniseed Syrup 1 2 2 12 - 550 ml bottles 10
Chef Anton’s Cajun 48 - 6 oz jars
4 2 2 3 22
Seasoning
Chef Anton’s 36 boxes
5 2 2 1 21.35
Gumbo Mix

Db : Suppliers
SupplierID SupplierName ContactNam Address City PostalCode Country Phone
e
1 Exotic Liquid Charlotte 49 Gilbert St. London EC1 4SD UK (171) 555 –
4 | Achmad Adyatma Ardi
2222
P.O. Box (100) 555 –
2 New Orleans Shelley New Orleans 70117 USA
78934 4822
Grandma Kelly’s 707 Oxford (313) 555 –
3 Regina Ann Arbor 48104 USA
Homestead Rd. 5735
9 – 8 Sekimai
(03) 3555 –
4 Tokyo Traders Yoshi Musashino – Tokyo 100 Japan
5011
shi

Db: Orders
OrderID CustomerID EmployeeID OrderDate ShipperID
10248 90 5 7/4/1996 3
10249 81 6 7/5/1996 1
10250 34 4 7/8/1996 2
10251 84 3 7/9/1996 1
10252 76 4 7/10/1996 2

Some of the most important SQL Commands 1. The SQL SELECT Statement

 SELECT – extracts data from a database Usage : select data from a database
 UPDATE – updates data in a database Syntax :
 DELETE – deletes data from a database 1. Specified field
 INSERT INTO – inserts new data into a database SELECT column1, column2,..
 CREATE DATABASE – creates a new database FROM table_name;
 ALTER DATABASE – modifies a database
 CREATE TABLE – creates a new table 2. All fields
 ALTER TABLE – modifies a table SELECT * FROM table_name;
 DROP TABLE – deletes a table Example :
 CREATE INDEX – creates an index (search key)
 DROP INDEX – deletes an index SELECT CustomerName, City FROM Customers;

Number of records : 4
CustomerName City
Alfreds Futterkiste Frankurt
Ana Trujillo Emparedados y México D.F.
helados

5 | Achmad Adyatma Ardi


Antonio Moreno Taquería México D.F.
Around the Horn London

SELECT * CustomerName
- All records of db Customers
2. The SQL SELECT DISTINCT Statement 3. The SQL WHERE Clause

Usage : return only distint (different) values Usage : used to extract only those records that fulfill a specified
Syntax : condition
SELECT DISTINCT column1, column2,… Syntax :
FROM table_name; SELECT column1, column2,…
Example : FROM table_name
WHERE condition;
SELECT DISTINCT Country FROM Customers; Example :

Number of records : 1 SELECT CustomerID, PostalCode, Country FROM Customers


Country WHERE Country = ‘Mexico’;
Mexico
Number of records : 2
To count lists of number of different (distinct) value : CustomerID PostalCode Country
2 05021 Mexico
SELECT COUNT (DISTINCT Country) FROM Customers; 3 05023 Mexico

Number of records : 1 Text field vs. Numeric Fields


COUNT (DISTINCT Country) - SQL requires single quotes around text values (most
1 database systems will allow double quotes).
- However, numeric fields should not be enclosed in quotes

SELECT CustomerID, City FROM Customers


WHERE CustomerID =1;

Number of records : 1
CustomerID City
1 Frankurt

Operators in the WHERE Clause


1. = (equal)
6 | Achmad Adyatma Ardi
WHERE Price = 18;
2. > (greater than)
WHERE Price > 18;
3. < (less than)
WHERE Price < 18;
4. >= (greater than or equal)
WHERE Price >= 18;
5. <= (less than or equal)
WHERE Price <= 18;
6. <> (not equal. Note : in some versions of SQL this operator
may be written as !=)
WHERE Price <> 18;
7. BETWEEN (between a certain range)
WHERE Price BETWEEN 50 AND 60;
8. LIKE (search for a pattern)
WHERE Country LIKE ‘me%’;
9. IN (to specify multiple possible values for a column)
WHERE CITY IN (‘Paris’, ‘London’);

SELECT CustomerID, City FROM Customers


WHERE Country LIKE ‘me%’;

CustomerID Country
2 Frankurt
3 México D.F
4. The SQL AND, OR and NOT Operators 5. The SQL ORDER BY Keyword

Usage : combine with WHERE clause, AND and OR operators are Usage : used to sort the result – set in ascending or descending
used to filter records based on more than one condition order. To sort the records in descending order, use the DESC
Syntax : keyword (ascending order by default)
1. AND Syntax :
SELECT column1, column2,… SELECT column1, column2, …
FROM table_name FROM table_name
WHERE condition1 AND condition2 AND condition3,…; ORDER BY column1, column2, …ASC |DESC;
Example :
2. OR
SELECT column1, column2,… SELECT CustomerID, ContactName FROM Customers
7 | Achmad Adyatma Ardi
FROM table_name ORDER BY CustomerID DESC;
WHERE condition1 OR condition2 OR condition3,…;
Number of records : 4
3. NOT CustomerID ContactName
SELECT column1, column2,… 4 Alfred Schmidt
FROM table_name 3 Ana Trujillo
WHERE NOT condition, 2 Antonio Moreno
1 Thomas Hardy
Example :
1. AND - ORDER BY several columns
SELECT CustomerID, Country FROM Customers
WHERE Country=’Germany’ AND City=’Frankurt’; SELECT CustomerID, ContactName, Country FROM
Customers
Number or records : 1 ORDER BY Country ASC, CustomerID DESC;
CustomerID Country
1 Germany Number of records : 4
CustomerID ContactName Country
2. OR 1 Thomas Hardy Germany
SELECT CustomerID, Country FROM Customers 3 Ana Trujillo Mexico
WHERE Country=’Germany’ OR City=’Tangerang’; 2 Antonio Moreno Mexico
4 Alfred Schmidt UK
Number of records : 1
CustomerID Country
1 Germany
Note. the city of tangerang is not in the Customers database
but it still evaluates to true because one of the conditions is
true

3. NOT
SELECT CustomerID, Country FROM Customers
WHERE NOT Country=’Germany’

Number of records : 3
CustomerID Country
2 Mexico
3 Mexico
4 UK
8 | Achmad Adyatma Ardi
Combining AND, OR and NOT
- You can also combine the AND, OR, and NOT operators
1. Example 1
SELECT CustomerID, PostalCode FROM Customers
WHERE Country = ‘Germany’ AND (City=London OR
City=’Frankurt’)

Number of records : 1
CustomerID PostalCode
1 12209

2. Example 2
SELECT CustomerID, CustomerName FROM Customers
WHERE NOT Country = ‘Mexico’ AND NOT City = ‘London’;

Number of records : 1
CustomerI CustomerName
D
1 Alfreds Futterkiste

6. The SQL INSERT INTO Statement 7. SQL NULL Values

Usage : insert new records in a table NULL Value ?


Syntax : - Is a field with no value
1. Specify both the column names and the values to be inserted - We use the IS NULL and IS NOT NULL operators to test
for NULL values
INSERT INTO table_name (column1, column2, column3, …) Syntax :
VALUES (value1, value2, value3,… ); 1. IS NULL
SELECT column_names
2. Do not need to specify the column names in the SQL query FROM table_name
WHERE column_name IS NULL;
INSERT INTO table_name
VALUES (value1, value2, value3, …); 2. IS NOT NULL
SELECT column_names
Note. make sure the order of the values is in the same order as FROM table_name
9 | Achmad Adyatma Ardi
the columns in the table. WHERE column_name IS NOT NULL;

Example : Example :
1. All records 1. IS NULL
SELECT CustomerName, ContactName, Address
INSERT INTO Customers (CustomerName, ContactName, FROM Customers
Address, City, PostalCode, Country) WHERE Address IS NULL;
VALUES (‘Achmad Adyatma Ardi’, ‘Achmad’, ‘Taman ubud’,
‘Tangerang’, ‘15810’, ‘Indonesia’); CustomerName ContactName Address
Laiba nafisah null null
Output : all records + new records (Customer ID = 5)

2. Insert data only in specified columns 2. IS NOT NULL


SELECT CustomerName, ContactName, Address
INSERT INTO Customers (CustomerName, City, Country) FROM Customers
VALUES (‘Laiba nafisah’, ‘Tangerang’, ‘Indonesia’); WHERE Address IS NOT NULL;
Output : all records + new records (CustomerID = 6) Output :
Note. tables that does not specifically contain a value will be All records that do not have a null value
null

8. The SQL UPDATE Statement 9. The SQL DELETE Statement

Usage : used to modify the existing records in a table Usage : used to delete records in a table
Syntax : Syntax :
UPDATE table_name 1. Specific row
SET column1 = value1, column2 = value2, … DELETE FROM table_name WHERE condition;
WHERE condition; 2. All rows
Warning : be careful when updating records in a table! Notice the DELETE FROM table_name
WHERE clause in the UPDATE statement. The WHERE clause
specifies which record(s) that should be updated. If you omit the Example :
WHERE clause, all records in the table will be updated! 1. Specific row
DELETE FROM Customers WHERE CustomerName =
Example : ‘Alfreds Futterkiste’;
1. Update one records
Output :
10 | Achmad Adyatma Ardi
UPDATE Customers delete records with CustomerName is ‘Alfreds
SET ContactName = ‘Laiba’, City = ‘Bogor’ Futterkiste’
WHERE CustomerID = 6;
2. All rows
Output : DELETE FROM Customers;
CustomerID = 7
Output :
2. Update multiple records Delete all rows in the ‘Customers’ table, without
UPDATE Customers deleting the table
SET ContactName = ‘Humaira’
WHERE Country = ‘Mexico’;

Output :
CustomerID = 8 & 9
10. The SQL TOP, LIMIT, FETCH FIRST or ROWNUM 11. The SQL MIN() and MAX() Functions
Clause
Usage : MIN() function returns the smallest value of the
Usage : used to specify the number of records to return, its useful selected column, meanwhile MAX() function returns the largest
because returning a large number of records can impact performance value of the selected column
Note : not all database system support the SELECT TOP clause. Syntax :
MySQL supports the LIMIT clause to select a limited number of 1. MIN ()
records, while Oracle uses FETCH FIRST n ROWS ONLY and SELECT MIN(column_name)
ROWNUM FROM table_name
Syntax : WHERE condition;
1. SQL Server / MS Access
SELECT TOP number|percent column_name(s) 2. MAX ()
FROM table_name SELECT MAX(column_name)
WHERE condition; FROM table_name
WHERE condition;
2. MySQL
SELECT column_name(s) Example :
FROM table_name 1. MIN()
WHERE condition SELECT MIN(Price) AS SmallestPrice
LIMIT number; FROM Products;

3. Oracle 12 Number of Records :


SELECT column_name(s) SmallestPrice
11 | Achmad Adyatma Ardi
FROM table_name 18
ORDER BY column_name(s)
FETCH FIRST number ROWS ONLY; 2. MAX()
SELECT MAX(Price) AS LargestPrice
4. Older Oracle FROM Products;
SELECT column_name(s)
FROM table_name Number of Records :
WHERE ROWNUM <= number; SmallestPrice
22
5. Older Oracle (with ORDER BY)
SELECT *
FROM (SELECT column_name(s) FROM table_name
ORDER BY column_name(s))
WHERE ROWNUM <= number;

Example :
1. SQL Server / MS Access
SELECT TOP 3 * FROM Customers;

Output : targeting top 3 positions of the records from the


‘Customers’ table

2. MySQL
SELECT * FROM Customers
LIMIT 3;

Output : targeting top 3 positions of the records from the


‘Customers’ table

3. Oracle
SELECT * FROM Customers
FETCH FIRST 3 ROWS ONLY;

Output : targeting top 3 positions of the records from the


‘Customers’ table

4. SQL Server / MS Access (PERCENT)

12 | Achmad Adyatma Ardi


SELECT TOP 50 PERCENT * FROM Customers;

Output : targeting the first 50% of the records from the


‘Customers’ table

5. Oracle (PERCENT)
SELECT * FROM Customers
FETCH FIRST 50 PERCENT ROWS ONLY;

Output : targeting the first 50% of the records from the


‘Customers’ table

6. SQL Server / MS Access (WHERE clause)


SELECT TOP 3 * FROM Customers
WHERE Country='Germany';

Output : targeting top 3 positions of the records from the


‘Customers’ table where the Country =’Germany’

7. MySQL (WHERE clause)


SELECT * FROM Customers
WHERE Country='Germany'
LIMIT 3;

Output : targeting top 3 positions of the records from the


‘Customers’ table where the Country =’Germany’

8. Oracle (WHERE clause)


SELECT * FROM Customers
WHERE Country='Germany'
FETCH FIRST 3 ROWS ONLY;

Output : targeting top 3 positions of the records from the


‘Customers’ table where the Country =’Germany’
12. The SQL COUNT(), AVG() and SUM() Functions 13. The SQL LIKE Operator

Usage : Usage : used in a WHERE clause to search for a specified


13 | Achmad Adyatma Ardi
- COUNT() returns the number of rows that matches a pattern in a column
specidied criterion
- AVG() returns the average value of a numeric column Note : You can also combine any number of conditions using
- SUM() returns the total sum of a numeric column AND or OR operators
Null ?
- NULL values are not counted Syntax :
- NULL values are ignored SELECT column1, column2,…
Syntax : FROM table_name
1. COUNT() WHERE column LIKE pattern;
SELECT COUNT(column_name)
FROM table_name Example :
WHERE condition; SELECT ProductID, ProductName FROM Products
WHERE ProductName LIKE ‘a%’;
2. AVG()
SELECT AVG(column_name) Output :
FROM table_name ProductI ProductName
WHERE condition; D
5 Aniseed Syrup
3. SUM()
SELECT SUM(column_name)
FROM table_name
WHERE condition;

Example :
1. COUNT()
SELECT COUNT(ProductID)
FROM Products;

Output :
COUNT(ProductyID)
5

2. AVG()
SELECT AVG(Price)
FROM Products;

Output :
14 | Achmad Adyatma Ardi
AVG(Price)
18.07

3. SUM()
SELECT SUM(Quantity)
FROM OrderDetails;

Output :
SUM(Quantity)
12

4. Using WHERE Clause


SELECT COUNT(ProductID)
FROM Products
WHERE Quantity = 2;

Output :
COUNT(ProductID)
2

14. The SQL Wildcards Characters 15. The SQL IN Operator

Usage : used to substitute one or more characters in a string, its used Usage : allows you to specify multiple values in a WHERE
with the LIKE operator. The LIKE operator is used in a WHERE clause, it’s a shorthand for multiple OR conditions
clause to search for a specified pattern in a column Syntax :
1. Way 1
Wildcard Characters : SELECT column_name(s)
MS Access FROM table_name
WHERE column_name IN (value1, value2, ...);
Symbol Description Example
Represents zero or more bl* finds bl, black, 2. Way 2
*
characters blue, and blob SELECT column_name(s)
h?t finds hot, hat, FROM table_name
? Represents a single character
and hit WHERE column_name IN (SELECT STATEMENT);
Represents any single character h[oa]t finds hot and
[] Example :
within the brackets hat, but not hit
15 | Achmad Adyatma Ardi
Represents any character not in
h[!oa]t finds hit, but 1. IN
!
the brackets not hot and hat SELECT ContactName, City FROM Customers
Represents any single character
c[a-b]t finds cat and WHERE City IN (‘Frankurt’, ‘London’, ‘Bogor’);
-
within the specified range cbt
2#5 finds 205, 215, Output :
Represents any single numeric 225, 235, 245, 255, ContactName City
# Alfred Schmidt Frankurt
character 265, 275, 285, and
295 Thomas Hardy London
Laiba Bogor
SQL Server
(Select all records that are ‘City’ located in ‘Frankurt’,
Symbol Description Example ‘London’, or ‘Bogor’)
Represents zero or more bl% finds bl, black,
% 2. NOT IN
characters blue, and blob
h_t finds hot, hat, SELECT ContactName, City FROM Customers
_ Represents a single character WHERE Country NOT IN (‘México D.F.’,
and hit
Represents any single character h[oa]t finds hot and ‘Tangerang’, ‘Bogor’);
[]
within the brackets hat, but not hit
Represents any character not in h[^oa]t finds hit, but Output :
^ ContactName City
the brackets not hot and hat
Represents any single character c[a-b]t finds cat and Alfred Schmidt Frankurt
- Thomas Hardy London
within the specified range cbt

Note : MySQL used % and _ wildcards only (Select all records that are ‘City’ NOT located in
‘México D.F.’, ‘Tangerang’, or, ‘Bogor’)
Example :
1. % 3. Other database
SELECT CustomerID, ContactName, Country FROM SELECT ContactName, City FROM Customers
Customers WHERE City IN (SELECT City FROM Suppliers);
WHERE Country LIKE ‘me%’;
ContactName City
Output : Thomas Hardy London
CustomerID ContactName Country
2 Ana Trujillo Mexico (Select all records that are from the same Cities as the
3 Antonio Moreno Mexico Suppliers)
8 Humaira Mexico

16 | Achmad Adyatma Ardi


9 Humaira Mexico

(Select all customers with a Country starting with ‘me’)

2. _
SELECT CustomerID, ContactName, Country FROM
Customers
WHERE Country LIKE ‘k’;

CustomerID ContactName Country


4 Thomas Hardy UK

(Select all customers with a Country starting with any


character, followed by ‘k’)

3. [ ]
SELECT * FROM Customers
WHERE Country LIKE ‘[gu]%’;

CustomerID ContactName Country


1 Alfred Schmidt Germany
4 Thomas Hardy UK

(Select all records with a Country starting with ‘g’ or ‘u’)

4. [ - ]
SELECT CustomerID, ContactName, Country FROM
Customers
WHERE Country LIKE ‘[i-m]%’;

CustomerID ContactName Country


2 Ana Trujillo Mexico
3 Antonio Moreno Mexico
5 Achmad Indonesia
6 null Indonesia
7 Laiba Indonesia
8 Humaira Mexico
17 | Achmad Adyatma Ardi
9 Humaira Mexico

(Select all records with a Country starting with the letter ‘i’ to
‘m’)

5. [!]
SELECT CustomerID, ContactName, Country FROM
Customers
WHERE Country LIKE ‘[!gmi]%’;

CustomerID ContactName Country


4 Thomas Hardy UK

(Select all records with a Country NOT starting with ‘g’, ‘m’
or ‘i’)

6. NOT LIKE [ ]
SELECT CustomerID, ContactName, Country FROM
Customers
WHERE Country NOT LIKE ‘[mu]%’;

CustomerID ContactName Country


1 Thomas Hardy Germany
5 Achmad Indonesia
6 null Indonesia
7 Laiba Indonesia

(Select all records with a Country NOT starting with ‘m’ or


‘u’)

16. The SQL BETWEEN Operator 17. The SQL Aliases

Usage : used to select values within a given range. The values can be Usage :
numbers, text, or dates. Begin and end values are included - SQL aliases are used to give a table, or a column in a
table, a temporary name. Aliases are often used to make
Syntax : column names more readable
SELECT column_name(s) - An alias only exists for the duration of that query
18 | Achmad Adyatma Ardi
FROM table_name - An alias is created with the AS keyword
WHERE column_name BETWEEN value1 AND value2 Syntax :
ORDER BY column_name ASC | DESC; (optional) 1. Alias column
Example : SELECT column_name AS alias_name
1. BETWEEN FROM table_name;
SELECT ProductName, Price FROM Products
WHERE Price BETWEEN 10 AND 20 2. Alias table
ORDER BY Price ASC; SELECT column_name(s)
FROM table_name AS alias_name;
ProductName Price
Aniseed Syrup 10 Example :
Chais 18 1. Alias for
Chang 19

2. NOT BETWEEN
SELECT ProductName, Price FROM Products
WHERE Price NOT BETWEEN 10 AND 20;
ORDER BY Price ASC;

ProductName Price
Chef Anton’s Gumbo Mix 21.35
Chef Anton’s Cajun Seasoning 22

3. BETWEEN with IN
SELECT ProductName, Price FROM Products
WHERE Price BETWEEN 10 AND 21.35
AND CategoryID NOT IN (1, 3);
ORDER BY ProductName DESC;

ProductName CategoryID Price


Chef Anton’s 2 21.35
Gumbo Mix
Aniseed Syrup 2 10

4. BETWEEN text values


SELECT ProductID, ProductName FROM Products
WHERE ProductName BETWEEN ‘Aniseed Syrup’ AND
19 | Achmad Adyatma Ardi
‘Chais’
ORDER BY ProductName ASC;

ProductID ProductName
3 Aniseed Syrup
1 Chais
2 Chang

5. NOT BETWEEN text values


SELECT ProductID, ProductName FROM Products
WHERE ProductName NOT BETWEEN ‘Aniseed Syrup’
AND ‘Chais’
ORDER BY ProductName ASC;

ProductID ProductName
4 Chef Anton’s Cajun
Seasoning
5 Chef Anton’s Gumbo
Mix

6. BETWEEN dates (#07/01/1996# or 1996-07-01)


a. #07/01/1996# (month/date/year)
SELECT OrderID, OrderDate FROM Orders
WHERE OrderDate BETWEEN #07/01/1996# AND
#07/05/1996#;

OrderID OrderDate
10248 7/4/1996
10249 7/5/1996

b. 1996-07-01 (year/month/date)
SELECT OrderID, OrderDate FROM Orders
WHERE OrderDate BETWEEN '1996-07-05' AND '1996-
07-09';

OrderID OrderDate
10249 7/5/1996
20 | Achmad Adyatma Ardi
10250 7/8/1996
10251 7/9/1996

18. The SQL Joins 19. The SQL INNER JOIN Keyword

Syntax : Syntax :
1. Specified field 1. Specified field
SELECT column1, column2,.. SELECT column1, column2,..
FROM table_name; FROM table_name;
2. All fields 2. All fields
SELECT * FROM table_name; SELECT * FROM table_name;
Example : Example :
SELECT CustomerName, City FROM Customers; SELECT CustomerName, City FROM Customers;

20. The SQL LEFT JOIN Keyword 21. The SQL RIGHT JOIN Keyword

Syntax : Syntax :
1. Specified field 1. Specified field
SELECT column1, column2,.. SELECT column1, column2,..
FROM table_name; FROM table_name;
2. All fields 2. All fields
SELECT * FROM table_name; SELECT * FROM table_name;
Example : Example :
SELECT CustomerName, City FROM Customers; SELECT CustomerName, City FROM Customers;

22. The SQL FULL OUTER JOIN Keyword 23. The SQL Self Join

Syntax : Syntax :
1. Specified field 1. Specified field
SELECT column1, column2,.. SELECT column1, column2,..
FROM table_name; FROM table_name;
2. All fields 2. All fields
SELECT * FROM table_name; SELECT * FROM table_name;
Example : Example :
SELECT CustomerName, City FROM Customers; SELECT CustomerName, City FROM Customers;

21 | Achmad Adyatma Ardi


24. The SQL UNION Operator 25. The SQL GROUP BY Statement

Syntax : Syntax :
1. Specified field 1. Specified field
SELECT column1, column2,.. SELECT column1, column2,..
FROM table_name; FROM table_name;
2. All fields 2. All fields
SELECT * FROM table_name; SELECT * FROM table_name;
Example : Example :
SELECT CustomerName, City FROM Customers; SELECT CustomerName, City FROM Customers;

26. The SQL HAVING Clause 27. The SQL EXISTS Operator

Syntax : Syntax :
1. Specified field 1. Specified field
SELECT column1, column2,.. SELECT column1, column2,..
FROM table_name; FROM table_name;
2. All fields 2. All fields
SELECT * FROM table_name; SELECT * FROM table_name;
Example : Example :
SELECT CustomerName, City FROM Customers; SELECT CustomerName, City FROM Customers;

28. The SQL ANY and ALL Operators 29. The SQL SELECT INTO Statement

Syntax : Syntax :
1. Specified field 1. Specified field
SELECT column1, column2,.. SELECT column1, column2,..
FROM table_name; FROM table_name;
2. All fields 2. All fields
SELECT * FROM table_name; SELECT * FROM table_name;
Example : Example :
SELECT CustomerName, City FROM Customers; SELECT CustomerName, City FROM Customers;

30. The SQL INSERT INTO SELECT Statement 31. The SQL CASE Statement

Syntax : Syntax :
1. Specified field 1. Specified field
22 | Achmad Adyatma Ardi
SELECT column1, column2,.. SELECT column1, column2,..
FROM table_name; FROM table_name;
2. All fields 2. All fields
SELECT * FROM table_name; SELECT * FROM table_name;
Example : Example :
SELECT CustomerName, City FROM Customers; SELECT CustomerName, City FROM Customers;

32. The SQL NULL Functions 33. The SQL Stored Procedures for SQL Server

Syntax : Syntax :
1. Specified field 1. Specified field
SELECT column1, column2,.. SELECT column1, column2,..
FROM table_name; FROM table_name;
2. All fields 2. All fields
SELECT * FROM table_name; SELECT * FROM table_name;
Example : Example :
SELECT CustomerName, City FROM Customers; SELECT CustomerName, City FROM Customers;

34. The SQL Comments 35. The SQL Operators

Syntax : Syntax :
1. Specified field 1. Specified field
SELECT column1, column2,.. SELECT column1, column2,..
FROM table_name; FROM table_name;
2. All fields 2. All fields
SELECT * FROM table_name; SELECT * FROM table_name;
Example : Example :
SELECT CustomerName, City FROM Customers; SELECT CustomerName, City FROM Customers;

36. The SQL CREATE DATABASE Statement 37. The SQL DROP DATABASE Statement

Syntax : Syntax :
1. Specified field 1. Specified field
SELECT column1, column2,.. SELECT column1, column2,..
FROM table_name; FROM table_name;
2. All fields 2. All fields
SELECT * FROM table_name; SELECT * FROM table_name;
23 | Achmad Adyatma Ardi
Example : Example :
SELECT CustomerName, City FROM Customers; SELECT CustomerName, City FROM Customers;

38. The SQL BACKUP DATABASE Statement 39. The SQL CREATE TABLE Statement

Syntax : Syntax :
1. Specified field 1. Specified field
SELECT column1, column2,.. SELECT column1, column2,..
FROM table_name; FROM table_name;
2. All fields 2. All fields
SELECT * FROM table_name; SELECT * FROM table_name;
Example : Example :
SELECT CustomerName, City FROM Customers; SELECT CustomerName, City FROM Customers;

40. The SQL DROP TABLE Statement 41. The SQL ALTER TABLE Statement

Syntax : Syntax :
1. Specified field 1. Specified field
SELECT column1, column2,.. SELECT column1, column2,..
FROM table_name; FROM table_name;
2. All fields 2. All fields
SELECT * FROM table_name; SELECT * FROM table_name;
Example : Example :
SELECT CustomerName, City FROM Customers; SELECT CustomerName, City FROM Customers;

42. The SQL Constraints 43. The SQL NOT NULL Constraint

Syntax : Syntax :
1. Specified field 1. Specified field
SELECT column1, column2,.. SELECT column1, column2,..
FROM table_name; FROM table_name;
2. All fields 2. All fields
SELECT * FROM table_name; SELECT * FROM table_name;
Example : Example :
SELECT CustomerName, City FROM Customers; SELECT CustomerName, City FROM Customers;

44. The SQL UNIQUE Constraint 45. The SQL PRIMARY KEY Constraint
24 | Achmad Adyatma Ardi
Syntax : Syntax :
1. Specified field 1. Specified field
SELECT column1, column2,.. SELECT column1, column2,..
FROM table_name; FROM table_name;
2. All fields 2. All fields
SELECT * FROM table_name; SELECT * FROM table_name;
Example : Example :
SELECT CustomerName, City FROM Customers; SELECT CustomerName, City FROM Customers;

46. The SQL FOREIGN KEY Constraint 47. The SQL CHECK Constraint

Syntax : Syntax :
1. Specified field 1. Specified field
SELECT column1, column2,.. SELECT column1, column2,..
FROM table_name; FROM table_name;
2. All fields 2. All fields
SELECT * FROM table_name; SELECT * FROM table_name;
Example : Example :
SELECT CustomerName, City FROM Customers; SELECT CustomerName, City FROM Customers;

48. The SQL DEFAULT Constraint 49. The SQL CREATE INDEX Statement

Syntax : Syntax :
1. Specified field 1. Specified field
SELECT column1, column2,.. SELECT column1, column2,..
FROM table_name; FROM table_name;
2. All fields 2. All fields
SELECT * FROM table_name; SELECT * FROM table_name;
Example : Example :
SELECT CustomerName, City FROM Customers; SELECT CustomerName, City FROM Customers;

50. The SQL AUTO INCREMENT Field 51. The SQL Working With Dates

Syntax : Syntax :
1. Specified field 1. Specified field
SELECT column1, column2,.. SELECT column1, column2,..
25 | Achmad Adyatma Ardi
FROM table_name; FROM table_name;
2. All fields 2. All fields
SELECT * FROM table_name; SELECT * FROM table_name;
Example : Example :
SELECT CustomerName, City FROM Customers; SELECT CustomerName, City FROM Customers;

52. The SQL Views 53. The SQL SELECT DISTINCT Statement

Syntax : Syntax :
1. Specified field 1. Specified field
SELECT column1, column2,.. SELECT column1, column2,..
FROM table_name; FROM table_name;
2. All fields 2. All fields
SELECT * FROM table_name; SELECT * FROM table_name;
Example : Example :
SELECT CustomerName, City FROM Customers; SELECT CustomerName, City FROM Customers;

54. The SQL Hosting 55. The SQL Data Types for MySQL, SQL Server, and
MS Access
Syntax :
1. Specified field Syntax :
SELECT column1, column2,.. 1. Specified field
FROM table_name; SELECT column1, column2,..
2. All fields FROM table_name;
SELECT * FROM table_name; 2. All fields
Example : SELECT * FROM table_name;
SELECT CustomerName, City FROM Customers; Example :
SELECT CustomerName, City FROM Customers;

Attachment. 2
Attachment. 3
Attachment. 4

26 | Achmad Adyatma Ardi

You might also like