The Practical SQL Handbook: Using SQL Variants / Edition 4

Other Format (Print)
Buy Used
Buy Used from BN.com
$41.17
(Save 41%)
Item is in good condition but packaging may have signs of shelf wear/aging or torn packaging.
Condition: Used – Good details
Used and New from Other Sellers
Used and New from Other Sellers
from $17.50
Usually ships in 1-2 business days
(Save 74%)
Other sellers (Other Format)
  • All (14) from $17.50   
  • New (5) from $40.40   
  • Used (9) from $17.50   

Overview

This latest edition of the best-selling implementation guide to the Structured Query Language teaches SQL fundamentals while providing practical solutions for critical business applications. The Practical SQL Handbook, Fourth Edition now includes expanded platform SQL coverage and extensive real-world examples based on feedback from actual SQL users.

The Practical SQL Handbook begins with a step-by-step introduction to SQL basics and examines the issues involved in designing SQL-based database applications. It fully explores SQL's most popular implementations from industry leaders, Oracle, Microsoft, Sybase, and Informix.

Highlights include:

  • Detailed coverage of SQL commands for creating databases, tables, and indexes, and for
  • adding, changing, and deleting data
  • Using the SELECT command to retrieve specific data
  • Handling NULL values (missing information) in a relational database
  • Joining tables, including self joins and outer joins (ANSI and WHERE-clause syntax)
  • Working with nested queries (subqueries) to get data from multiple tables
  • Creating views (virtual tables) to provide customized access to data
  • Using SQL functions

A bonus CD-ROM contains a time-limited, full-feature version of the Sybase® Adaptive Server Anywhere™ software as well as the sample database, scripts, and examples included in the book.

The Practical SQL Handbook is the most complete reference available for day-to-day SQL implementations.

Read More Show Less

Product Details

  • ISBN-13: 9780201703092
  • Publisher: Addison-Wesley
  • Publication date: 6/28/2001
  • Edition description: 4th Edition Book & CD-ROM
  • Edition number: 4
  • Pages: 469
  • Sales rank: 788,585
  • Product dimensions: 7.38 (w) x 9.16 (h) x 1.02 (d)

Meet the Author

Judith S. Bowman has been a database professional since the early 1980s. She is currently an independent consultant specializing in SQL and relational database issues and is the author of Practical SQL: The Sequel (Addison-Wesley, 2001). Sandra L. Emerson is an independent consultant and former Vice President of Publishing Programs for Sybase. Marcy Darnovsky, teaches at colleges throughout the San Francisco Bay area. She was formerly at Sybase.

Read More Show Less

Read an Excerpt

Chapter 4: Selecting Data from the Database

In This Chapter
  • SELECT Overview and Syntax
  • Choosing Columns: The SELECT Clause
  • Specifying Tables: The FROM Clause
  • Selecting Rows: The WHERE Clause

SELECT Overview and Syntax

In many ways, the SELECT statement is the real heart of SQL. It lets you find and view your data in a variety of ways. You use it to answer questions based on your data: how many, where, what kind of, even what if. Once you become comfortable with its sometimes dauntingly complex syntax, you'll be amazed at what the SELECT statement can do.

Because SELECT is so important, five chapters focus on it:

  • This chapter begins with the bare bones: the SELECT, FROM, and WHERE clauses, search conditions, and expressions.
  • Chapter 5 delves into some SELECT refinements: ORDER BY, the DISTINCT keyword, and aggregates.
  • Chapter 6 covers the GROUP BY clause, the HAVING clause, and making reports from grouped data. Chapter 6 also summarizes the issues regarding null values in database management.
  • Chapter 7 introduces multiple-table queries with a comprehensive discussion of joining tables.
  • Chapter 8 moves on to nested queries, also known as subqueries.
Queries in this chapter use single tables so that you can focus on manipulating the syntax in a simple environment. Following is an example of a SELECT query—don't worry about the syntax yet:
SQL
select address
from publishers
where pub_id ='0877'
address
========================================
2 2nd Ave.
[1 row ]

Basic SELECT Syntax

Discovering the structure of the SELECT statement begins with this skeleton:
  • The SELECT clause identifies the columns you want to retrieve.
  • The FROM clause specifies the tables those columns are in.
  • The WHERE clause qualifies the rows—it chooses the ones you want to see.
SELECT select_list
FROM table_list
WHERE search_conditions

Select_list and Search_condition Expressions Both the SELECT and WHERE clauses (in the select_list or search_conditions) can include

  • Plain column names )
  • Column names combined with other elements, such as calculations *1.085 )
  • Constants (character strings or display headings)
Collectively, these are expressions. Because the column name expression is the simplest case, examples often start there and then go on to a more complex expression. This does not mean that a column name is not an expression— it's just the place to start looking at expressions. Syntax that includes "expression" or "expr" or "char_expr" means that you can use a column name or a more complex expression....

Combining SELECT, FROM, and WHERE Artful combinations of the SELECT, FROM, and WHERE clauses produce meaningful answers to your questions and keep you from drowning in a sea of data. Think of the SELECT and WHERE clauses as horizontal and vertical axes on a matrix. (Figure 4.1 illustrates the query you saw at the beginning of the chapter.) The data you get from the SELECT statement is at the intersection of the SELECT (column) and WHERE (row) clauses.

Let's look at a SELECT statement with another bookbiz table, authors . The authors table stores information about authors: ID numbers, names, addresses, and phone numbers. If you want to know just the names of authors who live in California (not their addresses and phone numbers), use the SELECT clause and the WHERE clause to limit the data that the SELECT statement returns.

Here's a query that uses the SELECT clause's select_list to limit the columns you see. It lists just the names for the authors, ignoring their ID numbers, addresses, and phone numbers....

Read More Show Less

Table of Contents

List of Figures
Foreword to the Fourth Edition
Preface
Introduction
Ch. 1 SQL and Relational Database Management 1
Ch. 2 Designing Databases 21
Ch. 3 Creating and Filling a Database 51
Ch. 4 Selecting Data from the Database 95
Ch. 5 Sorting Data and Other Selection Techniques 143
Ch. 6 Grouping Data and Reporting from It 175
Ch. 7 Joining Tables for Comprehensive Data Analysis 205
Ch. 8 Structuring Queries with Subqueries 243
Ch. 9 Creating and Using Views 283
Ch. 10 Security, Transactions, Performance, and Integrity 315
Ch. 11 Solving Business Problems 345
App. A: Syntax Summary for the SQL Used in This Book 379
App. B: Industry SQL Equivalents 381
App. C: Glossary 387
App. D: The bookbiz Sample Database 403
App. E: Resources 451
Index 455
Read More Show Less

Preface

Why New Editions?

Many things have changed since this book was first published in 1989, and SQL is no exception. The SQL language has expanded tremendously, both in numbers of users and in numbers of commands. Sales of relational databases continue to rise at a strong and steady rate.

When we wrote the first edition of The Practical SQL Handbook, the American National Standards Institute (ANSI) had already approved the 1986 SQL standard. The International Standards Organization (ISO) adopted it in 1987. Both ANSI and ISO helped create the 1989 version. The 1986 standards were skimpy, lacking features that most commercial vendors offered. The 1989 standards were more complete but still left many important elements undefined.

For the first edition, we felt we should focus on industry practice: As always, each vendor was keeping a wary eye on what the others were doing and making core offerings similar enough to attract both customers migrating from competitors, as well as new users looking for database systems they could build on. Because of this, we left both the not-quite-jelled ANSI standards and particular vendor implementations to the experts in those fields and concentrated on the common ground: generic or "industry-practice" SQL. Our goal was to offer the intelligent amateur practical information on how to use the actually available SQL of that time.

The 1992 ANSI standard (often called SQL-2 or SQL-92) represented a new stage in SQL development. This standard was more comprehensive than the 1989 standard: In written form it contained more than four times as many pages as the earlier version. Database vendors have adopted large parts of the 1992 standard. With the widespread adoption of the SQL-92 standard, the industry practice and the ANSI/ISO standards began to converge.

Despite vendor-specific differences, there is a general, industrywide core of SQL commands that all users need to understand. Adopting standards doesn't happen overnight; it is a long process. At any point, vendors will have varying levels of conformance and will continue to produce vendor-specific variations. This book aims to give SQL users a mastery of the fundamentals of the language, with a side glance at the specifics of particular implementations.

Changes for Recent Editions

The changes for recent editions have been threefold:
  • To include more real-world examples
  • To emphasize the SQL-92 features that most vendors have imple-mented
  • To provide software for hands-on practice

Include More Real-World Examples

In talking to new and developing SQL users, we heard over and over of their need for more examples to follow, change, narrow, and broaden. Accordingly, the bulk of the added material in the second edition consisted of code "recipes." Chapter 11, Solving Business Problems, is a selection of code samples based on questions and answers that came over computer newsgroups. We reproduce interesting problems and solutions in terms of the sample bookbiz database used throughout the book. The chapter includes examples of using the CASE function for conditional logic, formatting results, and finding date data. A few samples fall into a different category. They aren't so much solutions to problems as indications of common errors. They include issues with DISTINCT and misunderstandings of what SQL can do.

Emphasize SQL-92

With the third edition, we revised the book to incorporate the SQL-92 features that most vendors had adopted. These include new datatypes, additions to the CREATE TABLE statement that allow built-in integrity constraints, modifications to the ORDER BY and GROUP BY clauses, the new escape character for the LIKE keyword, and changes to GRANT and REVOKE, among others.

Provide Software for Hands-On Practice

With the fully usable trial version of Sybase's Adaptive Server Anywhere (ASA) on the CD that accompanies this book, you can run the examples (and your variants) on a PC. We've always felt that the secret to learning SQL is practice. Now you can experiment to your heart's content, trying out code samples with data you know and checking the results to see if they are what you expect. When you're stumped by complicated code, break it into small, meaningful pieces and run the pieces separately to make sure you understand what each segment does. Then put them together in increasingly complex combinations–and have fun!

The Sybase Adaptive Server Anywhere software on the CD is a 60-day full-feature version that allows you to create objects as well as to query existing objects. ASA is built with an updated version of the bookbiz database: For the fourth edition, we increased book prices and made dates more recent. Also included on the CD are scripts to create the database on ASA (in case you damage the original) and on the other systems discussed in the book.

The Fourth Edition

The Practical SQL Handbook, Fourth Edition, continues to focus on industry-practice SQL, but the information included is at once more general and more specific than earlier editions. For the fourth edition, we had two objectives:
  • To expand our test base, running the examples on five different database systems
  • To show vendor-specific differences among systems

Test on More Systems

For the fourth edition, all examples were run on five systems (Sybase Adaptive Server Anywhere, Adaptive Server Enterprise, Microsoft SQL Server, Oracle, Informix), rather than on Sybase systems only, as in the third edition. This expanded test base makes the information more universal. We are no longer limited to what we can explore or verify on a particular system. If an important feature doesn't exist on Adaptive Server Anywhere (ASA, the RDBMS included on the CD), we can show code and results from Oracle or SQL Server.

Show Examples of Vendor-Specific Differences

On the other hand, this edition is more specific. It includes information on specific idiosyncrasies of the five SQL dialects, warning readers where to look for differences. In this, it reflects the real world–lots of database users are working with multiple systems, either sequentially or simultaneously. Interesting SQL differences are flagged as SQL Variants, in-text sections that show details of differences in SQL use by different vendors. For example, how single and double quotes are used, or database users added, or outer joins specified. You won't see code for every one of the five systems every time, but you'll get an introduction to the kind of differences that are likely in a particular area.

Acknowledgments

We would like to thank the following people for their contributions to this book: Donna Jeker and Stu Schuster for supplying timely support and encouragement; Jeff Lichtman and Howard Torf for offering advice, examples, anecdotes, and reality checks; Tom Bondur, Susie Bowman, John Cooper, and Wayne Duquesne for providing resource materials and other information; Paul Winsberg for reviewing the database design chapter in the first edition; Robert Garvey for technical review of the second edition; Karen Ali for facilitating the third edition's SQL Anywhere CD; and Theo Posselt for technical review of the third edition.

For the fourth edition, we would like to acknowledge Mike Radencich of iAnywhere Solutions (a Sybase Company), for providing the software and permissions for the Adaptive Server Anywhere CD; Lance Batten of Tilden Park Software and Sanford Jacobs of Paragon Software for comments and corrections; our reviewers, on whom we rely for timely and detailed feedback: Vijayanandan Venkatachalam, curriculum director of Oracle Corporation; David McGoveran of Alternative Technologies; Roger Snowden; Amy Sticksel of Sticksel Data Systems; Paul Irvine of Emerald Solutions; and Karl Batten-Bowman.

Read More Show Less

Customer Reviews

Be the first to write a review
( 0 )
Rating Distribution

5 Star

(0)

4 Star

(0)

3 Star

(0)

2 Star

(0)

1 Star

(0)

Your Rating:

Your Name: Create a Pen Name or

Barnes & Noble.com Review Rules

Our reader reviews allow you to share your comments on titles you liked, or didn't, with others. By submitting an online review, you are representing to Barnes & Noble.com that all information contained in your review is original and accurate in all respects, and that the submission of such content by you and the posting of such content by Barnes & Noble.com does not and will not violate the rights of any third party. Please follow the rules below to help ensure that your review can be posted.

Reviews by Our Customers Under the Age of 13

We highly value and respect everyone's opinion concerning the titles we offer. However, we cannot allow persons under the age of 13 to have accounts at BN.com or to post customer reviews. Please see our Terms of Use for more details.

What to exclude from your review:

Please do not write about reviews, commentary, or information posted on the product page. If you see any errors in the information on the product page, please send us an email.

Reviews should not contain any of the following:

  • - HTML tags, profanity, obscenities, vulgarities, or comments that defame anyone
  • - Time-sensitive information such as tour dates, signings, lectures, etc.
  • - Single-word reviews. Other people will read your review to discover why you liked or didn't like the title. Be descriptive.
  • - Comments focusing on the author or that may ruin the ending for others
  • - Phone numbers, addresses, URLs
  • - Pricing and availability information or alternative ordering information
  • - Advertisements or commercial solicitation

Reminder:

  • - By submitting a review, you grant to Barnes & Noble.com and its sublicensees the royalty-free, perpetual, irrevocable right and license to use the review in accordance with the Barnes & Noble.com Terms of Use.
  • - Barnes & Noble.com reserves the right not to post any review -- particularly those that do not follow the terms and conditions of these Rules. Barnes & Noble.com also reserves the right to remove any review at any time without notice.
  • - See Terms of Use for other conditions and disclaimers.
Search for Products You'd Like to Recommend

Recommend other products that relate to your review. Just search for them below and share!

Create a Pen Name

Your Pen Name is your unique identity on BN.com. It will appear on the reviews you write and other website activities. Your Pen Name cannot be edited, changed or deleted once submitted.

 
Your Pen Name can be any combination of alphanumeric characters (plus - and _), and must be at least two characters long.

Continue Anonymously
Sort by: Showing 1 Customer Reviews
  • Anonymous

    Posted April 28, 2003

    A reviewer, April 28, 2003

    I am brand new to dealing with an Oracle database and SQL. This book gave me many simple examples to try some simple queries. Explanations of the actual command (select, insert, group by, etc.) were brief and to the point. Good for the novice and those who only need to extract simple output. I can't speak for more experienced users, but I think the book is focused on beginners or those who don't need to get into great detail with SQL.

    Was this review helpful? Yes  No   Report this review
Sort by: Showing 1 Customer Reviews

If you find inappropriate content, please report it to Barnes & Noble
Why is this product inappropriate?
Comments (optional)