Book description
SQL for the Real World
Don’t just learn “generic” SQL. Learn SQL to get results with the world’s top database platforms–Oracle for the enterprise and Microsoft Access for the desktop. Based on John Patrick’s hands-on SQL course at the University of California, Berkeley Extension, this book shows exactly how to retrieve the data you want, when you need it, in any application–from ad hoc reports to the data warehouse. Thoroughly updated for the newest versions of Oracle, Access, and the SQL standard, this book contains more exercises, techniques, and solutions than ever before. You’ll learn exactly how to write SQL queries that are easy to understand, verify, modify, and extend–even if you’ve never worked with databases before.
SQL Fundamentals,Third Edition, teaches you how to
Build simple statements to retrieve, store, or modify data
Craft complex queries that draw information from multiple tables
Sort and summarize your data just the way you want it
Create and edit your own tables
Protect the integrity of your data
Create more efficient, high-performance queries
Work with unions, subqueries, self joins, cross joins, inner joins, and outer joins
Use the Oracle Data Dictionary
About the Web Site
The accompanying Web site, https://www.box.com/shared/ylbckg2fn0 , contains all the SQL code and tables from the book, including the full databases for several versions of Access and code for building the corresponding Oracle databases. It also provides solutions to many of the book’s problems and an open area for discussions with the author and other readers.
Table of contents
- Copyright
- Preface
-
1. Storing Information in Tables
- Introduction
-
The Parts of a Table
- 1-5. Data is stored in tables
- 1-6. A row represents an object and the information about it
- 1-7. A column represents one type of information
- 1-8. A cell is the smallest part of a table
- 1-9. Each cell should express just one thing
- 1-10. Primary key columns identify each row
- 1-11. Most tables are tall and thin
- Examples of Tables
- Key Points
-
2. Getting Information from a Table
- The Select Statement
- The Select Clause
-
The Where Clause
- 2-8. Overview of the where clause
- 2-9. Using an Equal condition in the where clause
- 2-10. Using a Less Than condition in the where clause
- 2-11. Using a Not Equal condition in the where clause
- 2-12. Using the in condition in the where clause
- 2-13. Using the between condition in the where clause
- 2-14. Using the like condition in the where clause
- 2-15. Using the is null condition in the where clause
- The Order By Clause
- Key Points
-
3. Compound Conditions in the Where Clause
- Compound Conditions in the Where Clause
- Constant Values
-
Punctuation Matters
- 3-7. Punctuation you need to know right now
-
3-8. Punctuation reference section
- How to avoid having spaces in names
- How to handle spaces in names
- Commas
- Single quotes
- Double quotes
- Apostrophes
- Pound signs
- SQL can be written in free format
- Double dashes (comment line)
- Periods and exclamation marks
- Ampersands
- Vertical bars
- Semicolons
- Colons
- Numbers — Commas, decimal points, and dollar signs
- Square brackets
- Asterisks
- Forward slashes
- Multiline comments
- Not Equal conditions
- Wildcards
- Regular expressions
- Case Sensitivity
- Three-Valued Logic
- Error Messages
- Some Exercises Solved for You
- Key Points
-
4. Saving Your Results
-
Saving Your Results in a New Table or View
- 4-1. Create a new table from the result of a select statement
- 4-2. Creating a new view from the results of a select statement
- 4-3. Similarities between tables and views
- 4-4. Differences between tables and views
- 4-5. Deleting a table
- 4-6. Deleting a view
- 4-7. One view can be built on top of another view
- 4-8. Preventative delete
- Modifying the Data in a Table with SQL
- Modifying the Data in a Table with the GUI
- Restrictions on Modifying the Data in a Table
- Key Points
-
Saving Your Results in a New Table or View
-
5. The Data Dictionary and Other Oracle Topics
- Commit, Rollback, and Transactions
- Modifying Data through a View
- The SQL Commands Page in Oracle
- Using the Oracle Data Dictionary — Part 1
- Key Points
- 6. Creating Your Own Tables
-
7. Formats, Sequences, and Indexes
- Formats
- Sequences
- Indexes
-
Using the Oracle Data Dictionary — Part 2
- 7-12. How to find information about the datatype of a column
- 7-13. How to find information about sequences
- 7-14. How to find information about indexes
- 7-15. How to find information about all your database objects
- 7-16. How to use the index of Data Dictionary tables
- 7-17. How to use the index of Data Dictionary columns
- An Exercise Solved for You
- Key Points
-
8. Data Integrity
- Constraints on One Table
-
Referential Integrity
- 8-7. The concept of RI
- 8-8. An example of RI
- 8-9. Inserts and updates to the data table prevented by RI
- 8-10. Inserts and updates to the data table allowed by RI
- 8-11. Updates and deletes to the lookup table prevented by RI
- 8-12. How to delete a code from the lookup table
- 8-13. How to change a code in the lookup table
- 8-14. RI as a relationship between the tables
- 8-15. Setting up RI in the Access GUI
- The Delete Options and Update Options of RI
- Variations of Referential Integrity
- How to Code Constraints in a Create Table Statement
- Key Points
- 9. Row Functions
-
10. Using Row Functions
- Specialized Row Functions
- Using the Documentation of Row Functions
-
Creating Patterns of Numbers and Dates
- 10-8. Create a simple pattern of numbers
- 10-9. Create a complex pattern of numbers
- 10-10. List all the days of one week
- 10-11. Create a calendar of workdays
- 10-12. How to find out how many days old you are
- 10-13. How to find the date when you will be 10,000 days old
- 10-14. Numbering the lines of a report in Oracle and Access
- 10-15. Optional: An easy way to solve an algebraic equation
- Key Points
- 11. Summarizing Data
-
12. Controlling the Level of Summarization
-
Dividing a Table into Groups of Rows
- 12-1. Summary of groups of data within a column
- 12-2. The group by clause
- 12-3. Groups formed on two or more columns
- 12-4. Null groups when there are two or more grouping columns
- 12-5. Summarized data cannot be mixed with nonsummarized data in the same select statement
- 12-6. Solution 1: Add more columns to the group by clause
- 12-7. Solution 2: Divide the query into two separate select statements
- 12-8. How to create a report with subtotals and a grand total
- 12-9. Counting to zero, part 2
- 12-10. Counting to zero, part 3
-
Eliminating Some of the Summarized Data
- 12-11. The having clause
- 12-12. The having clause contrasted with the where clause
- 12-13. The whole process of the select statement on a single table
- 12-14. The having clause does not add any more power to the select statement
- 12-15. Use a where clause to eliminate raw data
- 12-16. How to apply one column function to another column function and get around other restrictions
- Key Points
-
Dividing a Table into Groups of Rows
-
13. Inner Joins
- Introduction to Joins
- Inner Joins of Two Tables
- Variations of the Join Condition
- Applications of Joins
- Key Points
-
14. Outer Joins
- Introduction to Outer Joins
-
Applications of Outer Joins
- 14-8. Counting to zero, part 4
- 14-9. Combining an outer join with a selection of the data
- 14-10. A full outer join in sorted order
- 14-11. Finding the defects in a pattern
- 14-12. Comparing tables using two or more columns
- 14-13. Comparing two different full outer joins
- 14-14. Problem: Left and right outer joins can be difficult to handle
- Key Points
-
15. Union and Union All
- Union Basics
- Unconventional Unions
-
Applications of a Union
- 15-9. Determining if two tables are identical
- 15-10. Using a literal in a union to identify the source of the data
- 15-11. Attaching messages to flag exceptions, warnings, and errors
- 15-12. Dividing data from one column into two different columns
- 15-13. Applying two functions to different parts of the data
- 15-14. A union of three or more tables
- Set Intersection and Set Difference in Oracle
- Key Points
-
16. Cross Joins, Self Joins, and CrossTab Queries
-
Cross Joins
- 16-1. Definition of a cross join
- 16-2. Why are cross joins important?
- 16-3. An inner join is derived from a cross join
- 16-4. The properties of an inner join
- 16-5. An error in the join condition can appear to be a cross join
- 16-6. Using a cross join to list all the possible combinations
- 16-7. Other layouts when there are three or more dimensions
- 16-8. Avoid a cross join of large tables
- Self Joins
- CrossTab Queries in Access
- CrossTab Queries in Oracle
- Key Points
-
Cross Joins
- 17. Combining Tables in a Production Database
-
18. If-Then-Else, Parameter Queries, and Subqueries
- If-Then-Else Logic
- Parameter Queries
- Subqueries
- Applications of Subqueries
- Older Features of Subqueries
- Key Points
- 19. The Multiuser Environment
- 20. The Design of SQL
- A. Oracle Is Free: How to Get Your Copy
- B. Quick Start with Oracle
- C. Quick Start with Access
- D. Diagram of the Lunches Database
Product information
- Title: SQL Fundamentals, Third Edition
- Author(s):
- Release date: September 2008
- Publisher(s): Pearson
- ISBN: 9780137156146
You might also like
book
Head First SQL
Is your data dragging you down? Are your tables all tangled up? Well we've got the …
book
Learning SQL, 3rd Edition
As data floods into your company, you need to put it to work right away—and SQL …
book
T-SQL Fundamentals, Third Edition
Effectively query and modify data using Transact-SQL Master T-SQL fundamentals and write robust code for Microsoft …
book
SQL Antipatterns
Bill Karwin has helped thousands of people write better SQL and build stronger relational databases. Now …