O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The Language of SQL, Second Edition

Book Description

The Language of SQL, Second Edition
 
Many SQL texts attempt to serve as an encyclopedic reference on SQL syntax -- an approach that is often counterproductive, because that information is readily available in online references published by the major database vendors. 
 
For SQL beginners, it’s more important for a book to focus on general concepts and to offer clear explanations and examples of what various SQL statements can accomplish. This is that book.
 
A number of features make The Language of SQL unique among introductory SQL books.
 
First, you will not be required to download software or sit with a computer as you read the text. The intent of this book is to provide examples of SQL usage that can be understood simply by reading.
 
Second, topics are organized in an intuitive and logical sequence. SQL keywords are introduced one at a time, allowing you to grow your understanding as you encounter new terms and concepts. 
 
Finally, this book covers the syntax of three widely used databases: Microsoft SQL Server, MySQL, and Oracle. Special “Database Differences” sidebars clearly show you any differences in syntax among these three databases, and instructions are included on how to obtain and install free versions of the databases. 
 
This is the only book you need to gain a quick working knowledge of SQL and relational databases.
 
Learn How To...
  • Use SQL to retrieve data from relational databases
  • Apply functions and calculations to data
  • Group and summarize data in a variety of useful ways
  • Use complex logic to retrieve only the data you need
  • Update data and create new tables
  • Design relational databases so that data retrieval is easy and intuitive
  • Use spreadsheets to transform your data into meaningful displays
  • Retrieve data from multiple tables via joins, subqueries, views, and set logic 
  • Create, modify, and execute stored procedures
  • Install Microsoft SQL Server, MySQL, or Oracle
Contents at a Glance
 
1  Relational Databases and SQL
2  Basic Data Retrieval
3  Calculated Fields and Aliases
4  Using Functions
5  Sorting Data
6  Selection Criteria
7  Boolean Logic
8  Conditional Logic
9  Summarizing Data
10 Subtotals and Crosstabs
11 Inner Joins
12 Outer Joins
13 Self Joins and Views
14 Subqueries
15 Set Logic
16 Stored Procedures and Parameters
17 Modifying Data
18 Maintaining Tables
19 Principles of Database Design
20 Strategies for Displaying Data
 
A Getting Started with Microsoft SQL Server
B Getting Started with MySQL
C Getting Started with Oracle

Table of Contents

  1. Cover Page
  2. About This E-Book
  3. Title Page
  4. Copyright Page
  5. Contents at a Glance
  6. Table of Contents
  7. About the Author
  8. Acknowledgments
  9. We Want to Hear from You!
  10. Reader Services
  11. Introduction
    1. Topics and Features
    2. What’s New in the Second Edition
    3. Plan of the Book
    4. Companion Website
  12. 1. Relational Databases and SQL
    1. What Is SQL?
    2. Microsoft SQL Server, MySQL, and Oracle
    3. Relational Databases
    4. Primary and Foreign Keys
    5. Datatypes
    6. NULL Values
    7. The Significance of SQL
    8. Looking Ahead
  13. 2. Basic Data Retrieval
    1. A Simple SELECT
    2. Syntax Notes
    3. Comments
    4. Specifying Columns
    5. Column Names with Embedded Spaces
    6. Preview of the Full SELECT
    7. Looking Ahead
  14. 3. Calculated Fields and Aliases
    1. Literal Values
    2. Arithmetic Calculations
    3. Concatenating Fields
    4. Column Aliases
    5. Table Aliases
    6. Looking Ahead
  15. 4. Using Functions
    1. What Is a Function?
    2. Character Functions
    3. Composite Functions
    4. Date/Time Functions
    5. Numeric Functions
    6. Conversion Functions
    7. Looking Ahead
  16. 5. Sorting Data
    1. Sorting in Ascending Order
    2. Sorting in Descending Order
    3. Sorting by Multiple Columns
    4. Sorting by a Calculated Field
    5. Sort Sequences
    6. Looking Ahead
  17. 6. Selection Criteria
    1. Applying Selection Criteria
    2. WHERE Clause Operators
    3. Limiting Rows
    4. Limiting Rows with a Sort
    5. Pattern Matching
    6. Wildcards
    7. Looking Ahead
  18. 7. Boolean Logic
    1. Complex Logical Conditions
    2. The AND Operator
    3. The OR Operator
    4. Using Parentheses
    5. Multiple Sets of Parentheses
    6. The NOT Operator
    7. The BETWEEN Operator
    8. The IN Operator
    9. Boolean Logic and NULL Values
    10. Looking Ahead
  19. 8. Conditional Logic
    1. The CASE Expression
    2. The Simple CASE Format
    3. The Searched CASE Format
    4. Conditional Logic in ORDER BY Clauses
    5. Conditional Logic in WHERE Clauses
    6. Looking Ahead
  20. 9. Summarizing Data
    1. Eliminating Duplicates
    2. Aggregate Functions
    3. The COUNT Function
    4. Grouping Data
    5. Multiple Columns and Sorting
    6. Selection Criteria on Aggregates
    7. Conditional Logic in GROUP BY Clauses
    8. Conditional Logic in HAVING Clauses
    9. Ranking Functions
    10. Partitions
    11. Looking Ahead
  21. 10. Subtotals and Crosstabs
    1. Adding Subtotals with ROLLUP
    2. Adding Subtotals with CUBE
    3. Creating Crosstab Layouts
    4. Looking Ahead
  22. 11. Inner Joins
    1. Joining Two Tables
    2. The Inner Join
    3. Table Order in Inner Joins
    4. An Alternate Specification of Inner Joins
    5. Table Aliases Revisited
    6. Looking Ahead
  23. 12. Outer Joins
    1. The Outer Join
    2. Left Joins
    3. Testing for NULL Values
    4. Right Joins
    5. Table Order in Outer Joins
    6. Full Joins
    7. Cross Joins
    8. Looking Ahead
  24. 13. Self Joins and Views
    1. Self Joins
    2. Creating Views
    3. Referencing Views
    4. Benefits of Views
    5. Modifying and Deleting Views
    6. Looking Ahead
  25. 14. Subqueries
    1. Types of Subqueries
    2. Using a Subquery as a Data Source
    3. Using a Subquery in Selection Criteria
    4. Correlated Subqueries
    5. The EXISTS Operator
    6. Using a Subquery as a Calculated Column
    7. Common Table Expressions
    8. Looking Ahead
  26. 15. Set Logic
    1. Using the UNION Operator
    2. Distinct and Non-Distinct Unions
    3. Intersecting Queries
    4. Looking Ahead
  27. 16. Stored Procedures and Parameters
    1. Creating Stored Procedures
    2. Parameters in Stored Procedures
    3. Executing Stored Procedures
    4. Modifying and Deleting Stored Procedures
    5. Functions Revisited
    6. Looking Ahead
  28. 17. Modifying Data
    1. Modification Strategies
    2. Inserting Data
    3. Deleting Data
    4. Updating Data
    5. Correlated Subquery Updates
    6. Looking Ahead
  29. 18. Maintaining Tables
    1. Data Definition Language
    2. Table Attributes
    3. Table Columns
    4. Primary Keys and Indexes
    5. Foreign Keys
    6. Creating Tables
    7. Creating Indexes
    8. Looking Ahead
  30. 19. Principles of Database Design
    1. Goals of Normalization
    2. How to Normalize Data
    3. The Art of Database Design
    4. Alternatives to Normalization
    5. Looking Ahead
  31. 20. Strategies for Displaying Data
    1. Crosstab Layouts Revisited
    2. Excel and External Data
    3. Excel Pivot Tables
    4. Looking Ahead
  32. A. Getting Started with Microsoft SQL Server
    1. Installing SQL Server 2016 Express
    2. Installing SQL Server 2016 Management Studio Express
    3. Using SQL Server 2016 Management Studio Express
  33. B. Getting Started with MySQL
    1. Installing MySQL on Windows
    2. Installing MySQL on a Mac
    3. Using MySQL Workbench
  34. C. Getting Started with Oracle
    1. Installing Oracle Database Express Edition
    2. Using Oracle Database Express Edition
  35. Index
  36. Code Snippets