Introduction To MYSQL: Objectives
Introduction To MYSQL: Objectives
Introduction To MYSQL: Objectives
1
Introduction to MYSQL
Introduction to MYSQL
Objectives:
At the end of the module the student is expected to:
1. Understand the meaning of MYSQL and its functionalities
2. Understand the application of phpmyadmin.
3. Apply SQL statements using
a. Select
b. Select individual and multiple column
c. All column
d. District row
e. Sorting data
f. Filtering using where clause
g. Wildcard filtering
Introduction to MYSQL
MySQL is the world's most popular open source database. With its
leading database choice for web-based applications, used by high profile web
What is MySQL?
MySQL is a database system used on the web
MySQL is a database system that runs on a server
MySQL is ideal for both small and large applications
MySQL is very fast, reliable, and easy to use
MySQL uses standard SQL
MySQL compiles on a number of platforms
MySQL is free to download and use
MySQL is developed, distributed, and supported by Oracle
Corporation
MySQL is named after co-founder Monty Widenius's daughter: My
The data in a MySQL database are stored in tables. A table is a collection
of related data, and it consists of columns and rows.
Course Module
PHP + MySQL Database System
PHP combined with MySQL are cross-platform (you can develop in
Windows and serve on a Unix platform)
Database Queries
A query is a question or a request.
We can query a database for specific information and have a recordset
returned.
What is PhpMyAdmin?
you can create, alter, drop, delete, import and export MySQL database tables.
You can run MySQL queries, optimize, repair and check tables, change
2. Support for most MySQL functions like browse, drop, create, copy and
alter databases, tables, views, fields and indexes, execute MySQL
queries, manage stored procedures and functions;
3. Import data from CSV and SQL files;
4. Export data to various formats: CSV, SQL, XML, PDF, ISO/IEC 26300 -
OpenDocument Text and Spreadsheet, Word, Excel, LATEX and
others;
5. Searching globally in a database or a subset of it;
6. And much more.
In the upper part you will find the server hostname. The databases
which you will manage are stored on the same server as the software and
Course Module
Databases
In the Databases tab you will find a list with all the databases which
SELECT Statement
SELECT column_name,column_name
FROM table_name;
SQL Statement
SELECT prod_name
FROM products;
Result
Web Development
5
Introduction to MYSQL
Analysis
SQL Statement
Course Module
Result
Analysis
SQL Statement
Select *
FROM products;
Web Development
7
Introduction to MYSQL
Result
Analysis
SQL Statement
Course Module
Result
Analysis
SQL Statement
SELECT products.prod_name
FROM tutorial.products;
Result
Analysis
In this section we have specified the name of the table including the
symbol (.), we also specify the database name, in this example we
have use the database name tutorial.
Web Development
9
Introduction to MYSQL
Sorting Data
SELECT statements return all matched rows, possibly every row in the
specified table.
SQL Statement
SELECT prod_name
FROM products
ORDER BY prod_name;
Result
Analysis
To explicitly sort data retrieved using a SELECT statement, you use
the ORDER BY clause. ORDER BY takes the name of one or more
columns by which to sort the output.
Course Module
Sorting by Multiple Columns
SQL Statement
Result
SQL Statement
Result
Filtering Data
SQL Statement
Result
Analysis
This statement retrieves two columns from the products table, but
instead of returning all rows, it returns only rows with a prod_price
value of 2.50.
Course Module
The WHERE Clause Operators
Example 1
SQL Statement
Result
Analysis
This statement retrieves two columns from the products table, the
prod_name and prod_price where the prod_name is equal to ‘fuses
Example 2
SQL Statement
Result
Analysis
This statement retrieves two columns from the products table, the
prod_name and prod_price where prod_price < 10.
Example 3
SQL Statement
Result
Course Module
Analysis
This statement retrieves two columns from the products table, the
prod_name and prod_price where prod_price <=10.
SQL Statement
OR
Result
SQL Statement
Analysis
When BETWEEN is used, two values must be specified, the low end
and high end of the desired range. The two values must also be
separated by the AND keyword. BETWEEN matches all the values in
the range, including the specified range start and end values.
SQL Statement
SELECT cust_id
FROM customers
WHERE cust_email IS NULL;
Result
Analysis
Here the query retrieves the columns with empty cust_email.
Course Module
Advanced Data Filtering
SQL Statement
Result
Analysis
The preceding SQL statement retrieves the product name and price
for all products made by vendor 1003 as long as the price is 10 or less.
The WHERE clause in this SELECT statement is made up of two
conditions, and the keyword AND is used to join them. AND instructs
the SQL Server to return only rows that meet all the conditions
specified. If a product is made by vendor 1003 but it costs more than
10, it is not retrieved. Similarly, products that cost less than 10 that
are made by a vendor other than the one specified are not retrieved.
SQL Statement
Result
Analysis
This SQL statement retrieves the product name and price for any
products made by either of the two specified vendors. The OR
operator tells the DBMS to match either condition, not necessarily
both. If an AND operator would have been used here, no data would
be returned. (It would have created a WHERE clause that could never
be matched.)
SQL Statement
Same as
Analysis
The SELECT statement retrieves all products made by vendor 1002
and vendor 1003. The IN operator is followed by a comma-delimited
list of valid values, and the entire list must be enclosed within
parentheses.
The WHERE clause’s NOT operator has one function and one
function only: NOT negates whatever condition comes next.
SQL Statement
Result
Web Development
19
Introduction to MYSQL
Analysis
The NOT here negates the condition that follows it; so instead of
matching vend_id to ‘1002 or ‘1003’, SQL Server matches vend_id to
anything that is not ‘1003 or ‘1002
SQL Statement
Result
Analysis
The search pattern ‘’jet%’ means match any value that contains the
text teddy anywhere within it, regardless of any characters before or
after that text.
Course Module
SQL Statement
Result
Analysis
The search pattern '%anvil%' means match any value that contains
the text anvil anywhere within it, regardless of any characters before
or after that text.
SQL STATEMENT
SELECT prod_name
FROM products
WHERE prod_name LIKE 's%e'
RESULT
Analysis
Wildcards can also be used in the middle of a search pattern, although
that is rarely useful. The following example finds all products that
begin with an s and end with an e:
Web Development
21
Introduction to MYSQL
Another useful wildcard is the underscore (_). The underscore is used just
like %, but instead of matching multiple characters, the underscore matches
just a single character.
SQL Statement
Result
Analysis
The search pattern used in this WHERE clause specifies a wildcard
followed by literal text. The results shown are the only rows that
match the search pattern: The underscore matches 1 in the first row
and 2 in the second row. The .5 ton anvil product did not match
because the search pattern matched a single character, not two. By
contrast, the following SELECT statement uses the % wildcard and
returns three matching products:
SQL Statement
Course Module
Result
Analysis
Unlike %, which can match zero characters, _ always matches one
character no more and no less.
References
Murach, J. (2014) Murach’s PHP and MYSQL (2nd Edition)
WEBSITE
http://php.net/
http://www.w3schools.com/php/
https://www.tutorialspoint.com/php/