Documente Academic
Documente Profesional
Documente Cultură
Student Guide
D61918GC20
Edition 2.0
March 2012
D76212
Author
Patricia Garcia
Disclaimer
Kimseong Loh
Rob Young
Philip Olson
Reggie Burnett
Todd Farmer
The information contained in this document is subject to change without notice. If you
find any problems in the document, please report them in writing to: Oracle University,
500 Oracle Parkway, Redwood Shores, California 94065 USA. This document is not
warranted to be error-free.
Edwin Desouza
Jesper Krogh
Sveta Smirnova
Jeremy Smyth
Brian Guy
Editor s
Aju Kumar
Trademark Notice
Richard Wallis
Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names
may be trademarks of their respective owners.
Gr aphic Designer
Rajiv Chandrabhanu
Publisher s
Giri Venugopal
Revathi V. Ramamoorthy
Contents
Preface
1
Introduction to MySQL
Course Goals 1-2
Course Lesson Map 1-4
Introductions 1-6
Classroom Environment 1-7
MySQL Overview 1-8
Acquisitions of the MySQL Company 1-9
MySQL Is Powering the World! 1-10
MySQL Database Server Editions 1-11
MySQL Tools 1-12
MySQL Connectors and APIs 1-13
MySQL Services 1-15
MySQL Community Support 1-16
Oracle Lifetime Support for MySQL 1-17
MySQL-Supported Operating Systems 1-18
MySQL Websites 1-19
MySQL Curriculum Footprint 1-20
MySQL Certification 1-21
MySQL Online Documentation 1-22
Example Databases 1-23
Summary 1-24
Practice 1-1 Overview: Access MySQL Information from Company Websites 1-25
iii
iv
Quiz 4-22
Database Design Considerations 4-23
Database Design Plan 4-24
Database Design Plan Diagram 4-25
Viewing a Database 4-26
Evaluating a Database Design 4-27
Summary 4-30
Practice 4-1 Overview: QuizDatabase Design 4-31
Practice 4-2 Overview: Evaluate a Database 4-32
Practice 4-3 Overview: Create a Structure Diagram 4-33
5
Basic Queries
Objectives 7-2
SELECT Statement 7-3
Using SELECT Clauses 7-5
Using SELECT with DISTINCT 7-6
SELECT DISTINCT with NULL 7-8
SELECT with WHERE 7-9
SELECT with ORDER BY 7-13
SELECT with ORDER BY with ASC and DESC 7-15
SELECT with LIMIT 7-17
SELECT with LIMIT and Skip Count 7-18
SELECT with LIMIT and ORDER BY 7-19
SELECT Usage Tips 7-20
Troubleshooting 7-21
SQL Modes for Syntax Checking 7-23
Common SQL Modes 7-24
Quiz 7-25
MySQL Workbench for SQL Development 7-26
Summary 7-27
Practice 7-1 Overview: Perform Basic Queries 7-28
Practice 7-2 Overview: Perform Basic Queries Using MySQL Workbench 7-29
Practice 7-3 Overview: Perform Basic Queries on the Pets Database 7-30
vi
vii
Practice 9-1 Overview: Insert and Replace Table Row Data 9-20
Practice 9-2 Overview: Modify and Delete Table Row Data 9-21
Practice 9-3 Overview: Manipulate Table Row Data in the Pets Database 9-22
10 Functions
Objectives 10-2
Functions in MySQL Expressions 10-3
Function Tips 10-4
Function Categories 10-5
String Functions 10-6
String Function: Numeric Category Examples 10-7
String Function: String Category Examples (CONCAT, REVERSE,
LEFT, RIGHT) 10-8
String Function: String Category Examples (LOWER, UPPER, LPAD, RPAD) 10-9
String Function: String Category Examples (TRIM) 10-10
String Function: String Category Examples (SUBSTRING) 10-11
String Function: String Category Examples (SUBSTRING_INDEX) 10-12
Temporal Functions 10-13
Temporal Functions: Date/Time Formats 10-14
Temporal Functions: Function Types 10-15
Temporal Functions: Extracting Temporal Data Examples 10-16
Numeric Functions 10-18
Numeric Functions: Examples 10-19
Numeric Functions: Additional Functions 10-20
Control Flow Functions 10-21
Control Flow Functions: CASE Functions 10-22
Control Flow Functions: CASE Function Syntax 10-23
Control Flow Functions: CASE Function Examples 10-24
Quiz 10-25
Aggregate Functions 10-26
Aggregate Function Types 10-27
Aggregate Functions: COUNT Function Examples 10-28
Aggregate Functions: GROUP BY Clause 10-29
Aggregate Functions: GROUP BY Clause and GROUP_CONCAT Function 10-30
Aggregate Functions: GROUP BY and HAVING Clauses 10-31
Aggregate Functions: GROUP BY Clause and WITH ROLLUP Modifier 10-32
Aggregate Functions: Super Aggregate Operation 10-33
Spaces in Function Names 10-34
Summary 10-35
Practice 10-1 Overview: Quiz 10-36
Practice 10-2 Overview: Use Built-In, String, and Temporal Functions 10-37
viii
Practice 10-3 Overview: Use Numeric and Control Flow Functions 10-38
Practice 10-4 Overview: Use Aggregate Functions 10-39
11 Joining Tables
Objectives 11-2
Combining Multiple Tables 11-3
Joining Tables with SELECT 11-4
Categories of Joins 11-5
Comma-Separated Joins 11-6
INNER JOIN Keywords 11-8
JOIN Keywords 11-9
Outer Joins 11-10
LEFT JOIN Keywords 11-12
RIGHT JOIN Keywords 11-13
Outer Joins: USING and NULL 11-14
Table Name Aliases 11-15
Quiz 11-16
Summary 11-17
Practice 11-1 Overview: Perform Inner and Outer Joins 11-18
Practice 11-2 Overview: Create Queries Requiring Joins 11-19
Practice 11-3 Overview: Additional Optional Practice 11-20
12 Table Subqueries
Objectives 12-2
Subquery: Overview 12-3
Basic Subquery: Example 12-4
Advantages of Using a Subquery 12-5
Placement of Subqueries 12-6
Subquery Categories 12-7
Non-Correlated Subquery: Example 12-8
Correlated Subquery: Example 12-9
Subquery Result Table Types 12-10
Scalar Subqueries 12-11
Subquery Type/Placement Chart 12-12
Column Designation Subquery 12-13
FROM Subquery 12-14
WHERE Subquery 12-15
WHERE Subquery with Operators 12-16
Subqueries in Comparisons 12-17
WHERE with IN or NOT IN 12-18
WHERE with ALL, ANY, and SOME 12-19
ix
xi
xii