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

W9 Lesson 7 Introduction To MySQL - Presentation

1) The document introduces MySQL and provides objectives which include understanding MySQL functionality and applying SQL statements like select, where, and order by. 2) Key points about MySQL are that it is an open source database commonly used by websites, it is very fast and easy to use, and it uses SQL. PhpMyAdmin is a free tool for managing MySQL databases. 3) Examples show how to use SQL statements like select, where, order by, between to retrieve, filter, and sort data from database tables. Operators like =, <, >, BETWEEN, IN can be used in where clauses.

Uploaded by

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

W9 Lesson 7 Introduction To MySQL - Presentation

1) The document introduces MySQL and provides objectives which include understanding MySQL functionality and applying SQL statements like select, where, and order by. 2) Key points about MySQL are that it is an open source database commonly used by websites, it is very fast and easy to use, and it uses SQL. PhpMyAdmin is a free tool for managing MySQL databases. 3) Examples show how to use SQL statements like select, where, order by, between to retrieve, filter, and sort data from database tables. Operators like =, <, >, BETWEEN, IN can be used in where clauses.

Uploaded by

Wendell
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 29

Week 009

Introduction to MYSQL
Objectives
• At the end of the module the student is expected to:
• Understand the meaning of MYSQL and its functionalities
• Understand the application of phpmyadmin.
• Apply SQL statements using
• Select
• Select individual and multiple column
• All column
• District row
• Sorting data
• Filtering using where clause
• Wildcard filtering
Introduction to MYSQL
• MySQL is the world's most popular open source database. With its proven

performance, reliability and ease-of-use, MySQL has become the leading

database choice for web-based applications, used by high profile web

properties including Facebook, Twitter, YouTube, Yahoo! and many more.


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
What is PhpMyAdmin?
• PhpMyAdmin is one of the most popular applications for MySQL
databases management. It is a free tool written in PHP. Through this
software you can create, alter, drop, delete, import and export MySQL
database tables. You can run MySQL queries, optimize, repair and
check tables, change collation and execute other database
management commands.
SELECT Statement
SQL Statement Result Analysis

SELECT statement to retrieve a single


SELECT prod_name column called prod_name from the
FROM products; products table.
Retrieving Multiple Columns
SQL Statement Result Analysis

SELECT prod_id, This statement uses the


prod_name, prod_price SELECT statement to retrieve
FROM products; data from the products table. In
this example, three column
names are specified, each
separated by a comma.
Retrieving All Columns
SQL Result Analysis
Statement

Select * Wildcard (*) is specified, all the


FROM columns in the table are
products; returned. The columns are in
the order in which they appear
in the table definition.
Retrieving Distinct Rows
SQL Statement Result Analysis

SELECT DISTINCT vend_id SELECT DISTINCT vend_id


FROM products; tells SQL Server to only return
distinct (unique) vend_id rows,
and therefore only three rows
are returned.
Using Fully Qualified Table Names
SQL Statement Result Analysis
SELECT In this section we have
products.prod_name specified the name of the table
FROM tutorial.products; including the symbol (.), we
also specify the database
name, in this example we have
use the database name
tutorial.
Sorting Data
SQL Statement Result Analysis
SELECT prod_name To explicitly sort data retrieved
FROM products using a SELECT statement,
ORDER BY you use the ORDER BY
prod_name; clause. ORDER BY takes the
name of one or more columns
by which to sort the output.
Sorting by Multiple Columns
SQL Statement Result Analysis
SELECT prod_id, Data sorting is not limited to
prod_price, prod_name ascending sort orders (from A to
FROM products Z). Although this is the default sort
ORDER BY prod_price, order, the ORDER BY clause can
prod_name; also be used to sort in descending
order (from Z to A). To sort by
descending order, you must
specify the keyword DESC
Sorting by Multiple Columns
SQL Statement Result Analysis
SELECT prod_id, Result is now displayed in
prod_price, prod_name DESC
FROM products
ORDER BY prod_price
DESC;
Filtering Data Using the WHERE Clause
SQL Statement Result Analysis

SELECT prod_name, This statement retrieves two


prod_price columns from the products
FROM products table, but instead
WHERE prod_price = 2.50; of returning all rows, it returns
only rows with a prod_price
value of
2.50.
The WHERE Clause Operators
Examples of WHERE Clause
SQL Statement Result Analysis
SELECT prod_name, This statement retrieves two
prod_price columns from the products
FROM products table, the prod_name and
WHERE prod_name = 'fuses'; prod_price where the
prod_name is equal to ‘fuses

SQL Statement Result Analysis

SELECT prod_name, This statement retrieves two


prod_price columns from the products
FROM products table, the prod_name and
WHERE prod_price < 10; prod_price where prod_price <
10.
Examples of WHERE Clause

SQL Statement Result Analysis

SELECT prod_name, This statement retrieves two


prod_price columns from the products
FROM products table, the prod_name and
WHERE prod_price <= 10; prod_price where prod_price
<=10.
Checking for Nonmatches
SQL Statement Result Analysis

SELECT vend_id, prod_name Using <> or != result of retrieve


FROM products data not that is not equal to the
WHERE vend_id <> 1003; WHERE clause

OR

SELECT vend_id, prod_name


FROM products
WHERE vend_id != 1003;
Checking for a Range of Values
SQL Statement Result Analysis

SELECT prod_name, prod_price When BETWEEN is used, two


FROM products values must be specified, the low
WHERE prod_price BETWEEN 5 end and high end of the desired
AND 10; 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.
Checking for No Value

SQL Statement Result Analysis

SELECT cust_id Here the query retrieves the


FROM customers columns with empty
WHERE cust_email IS NULL; cust_email
Advanced Data Filtering Combining WHERE Clauses
with AND OPERATOR
SQL Statement Result Analysis

SELECT prod_id, The preceding SQL statement retrieves the


product name and price for all products
prod_price, prod_name made by vendor 1003 as long as the price is
FROM products 10 or less.
WHERE vend_id =
1003 AND prod_price The WHERE clause in this SELECT
statement is made up of two conditions, and
<= 10; 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.
Using the OR Operator
SQL Statement Results Analysis
SELECT prod_name, This SQL statement retrieves
prod_price,vend_id the product name and price for
FROM products any products made by either of
WHERE vend_id = 1002 the two specified vendors. The
OR vend_id = 1003; 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.)
Using the IN Operator
SQL Statement Result Analysis
SELECT prod_name, prod_price, The SELECT statement retrieves
vend_id all products made by vendor 1002
FROM products and vendor 1003. The IN operator
WHERE vend_id IN (1002,1003) is followed by a comma-delimited
ORDER BY prod_name; list of valid values, and the entire
list must be enclosed within
Same as parentheses.

SELECT prod_name, prod_price


FROM products
WHERE vend_id = 1002 OR
vend_id = 1003
ORDER BY prod_name;
Using the NOT Operator

SQL Statement Result Analysis

SELECT prod_name, The NOT here negates the


prod_price, vend_id condition that follows it; so
FROM products instead of matching vend_id
WHERE vend_id NOT IN to ‘1002 or ‘1003’, SQL Server
(1002,1003) matches vend_id to anything
ORDER BY prod_name; that is not ‘1003 or ‘1002
Using Wildcard Filtering

SQL Statement Results Analysis

SELECT prod_id, prod_name The search pattern ‘’jet%’ means


FROM products match any value that contains the
WHERE prod_name LIKE 'jet%' text teddy anywhere within it,
regardless of any characters
before or after that text.
Using Wildcard Filtering
SQL Statement Results Analysis
SELECT prod_id, prod_name The search pattern '%anvil%'
FROM products means match any value that
WHERE prod_name LIKE contains the text anvil
'%anvil%'; anywhere within it, regardless
of any characters before or
after that text.
Using Wildcard Filtering
SQL Statement Result Analysis

SELECT prod_name Wildcards can also be used in


FROM products the middle of a search pattern,
WHERE prod_name LIKE 's%e' although that is rarely useful.
The following example finds all
products that begin with an s and
end with an e:
The Underscore (_) Wildcard
SQL Statement Result Analysis

SELECT prod_id, prod_name The search pattern used in this


FROM products WHERE clause specifies a wildcard
WHERE prod_name LIKE '_ ton followed by literal text. The results
anvil'; 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:
The % Wildcard
SQL Statement Result Analysis
SELECT prod_id, prod_name Unlike %, which can match zero
FROM products characters, _ always matches one
WHERE prod_name LIKE '% ton character no more and no less.
anvil';

You might also like