Cover image for SQL Pocket Guide, 3rd Edition

Book description

If you're a programmer or database administrator who uses SQL in your day-to-day work, this popular pocket guide is the ideal on-the-job reference. It uses numerous examples to address the language's complexity, and covers key aspects of SQL used in Oracle, DB2, SQL Server, MySQL, and PostgreSQL. That includes the syntax for querying, managing transactions, and making changes to data, as well as SQL functions, type conversion functions and formats, and regular expression syntax.

Table of Contents

  1. SQL Pocket Guide
  2. A Note Regarding Supplemental Files
  3. 1. SQL Pocket Guide
    1. Introduction
      1. Organization of This Book
        1. Platform notes
      2. Conventions
      3. Example Data
      4. Using Code Examples
      5. How to Contact Us
      6. Safari® Books Online
      7. Acknowledgments
    2. Analytic Functions
    3. CASE Expressions: Simple
    4. CASE Expressions: Searched
    5. CAST Function
    6. CONNECT BY Queries
      1. Core CONNECT BY Syntax
      2. Creative CONNECT BY
      3. WHERE Clauses with CONNECT BY
      4. Joins with CONNECT BY
      5. Sorting CONNECT BY Results
      6. Loops in Hierarchical Data
      7. Supporting Functions and Operators
    7. Data Type Conversion
    8. Data Types: Binary Integer
    9. Data Types: Character String
    10. Data Types: Datetime
      1. DB2
      2. MySQL
      3. Oracle
      4. PostgreSQL
      5. SQL Server
    11. Data Types: Decimal
      1. DB2’s DECFLOAT Type
      2. DECIMAL/NUMBER Type
    12. Datetime Conversions: DB2
    13. Datetime Conversions: MySQL
      1. Date and Time Elements
      2. TO_DAYS and FROM_DAYS
      3. Unix Timestamp Support
      4. Seconds in the Day
      5. DATE_FORMAT and TIME_FORMAT
    14. Datetime Conversions: Oracle
    15. Datetime Conversions: PostgreSQL
    16. Datetime Conversions: SQL Server
      1. CAST and SET DATEFORMAT
      2. CONVERT
      3. DATENAME and DATEPART
      4. DAY, MONTH, and YEAR
    17. Datetime Functions: DB2
    18. Datetime Functions: MySQL
    19. Datetime Functions: Oracle
      1. Getting Current Date and Time
      2. Rounding and Truncating
      3. Other Oracle Datetime Functions
    20. Datetime Functions: PostgreSQL
      1. Getting Current Date and Time
      2. Rounding and Truncating
      3. Other PostgreSQL Datetime Functions
    21. Datetime Functions: SQL Server
    22. Deleting Data
      1. Deleting in Order
      2. Deleting All Rows
      3. Deleting from Views and Subqueries
      4. Returning Deleted Data: DB2
      5. Returning Deleted Data: Oracle
      6. Returning Deleted Data: SQL Server
      7. Double-FROM
    23. EXTRACT Function
    24. GREATEST
    25. Grouping and Summarizing
      1. Aggregate Functions
      2. GROUP BY
      3. Listing the Detail Values
      4. Reducing the GROUP BY List
      5. Grouping Before the Join
      6. HAVING
      7. ROLLUP
      8. CUBE
      9. GROUPING SETS
      10. Related Functions
    26. Hierarchical Queries
      1. Recursive WITH
      2. Tracking Your Depth
      3. Breadth-First Versus Depth-First Sorting
      4. Detecting Recursive Loops
    27. Indexes, Creating
    28. Indexes, Removing
    29. Inserting Data
      1. Single-Row Inserts
      2. Multirow Inserts
      3. Insert Targets
      4. Subquery Inserts
      5. Returning Inserted Values: DB2
      6. Returning Inserted Values: Oracle
      7. Returning Inserted Data: SQL Server
      8. Multitable Inserts
        1. Unconditional multitable insert
        2. Conditional multitable insert
        3. ALL versus FIRST
    30. Joining Tables
      1. The Concept of a Join
      2. Cross Joins
      3. Inner Joins
      4. The USING Clause
      5. Natural Joins
      6. Non-Equi-Joins
      7. Outer Joins
        1. Left outer joins
        2. Interpreting nulls in an outer join
        3. Right outer joins
        4. Full outer joins
        5. Vendor-specific outer join syntax
    31. LEAST
    32. Literals
      1. Text Literals
      2. Numeric Literals
      3. Datetime Literals
      4. Datetime Interval Literals
    33. Merging Data
    34. Nulls
      1. Predicates for Nulls
      2. Using CASE with Nulls
      3. Using the COALESCE Function
      4. Functions for Nulls: DB2
      5. Functions for Nulls: MySQL
      6. Functions for Nulls: Oracle
      7. Functions for Nulls: PostgreSQL
      8. Functions for Nulls: SQL Server
    35. Numeric Conversions: DB2
    36. Numeric Conversions: MySQL
    37. Numeric Conversions: Oracle
    38. Numeric Conversions: PostgreSQL
    39. Numeric Conversions: SQL Server
    40. Numeric/Math Functions
    41. OLAP Functions
    42. Pivoting and Unpivoting
      1. Pivoting: The Concept
      2. Pivoting: Oracle
      3. Pivoting: SQL Server
      4. Unpivoting: The Concept
      5. Unpivoting: Oracle
      6. Unpivoting: SQL Server
    43. Predicates
      1. EXISTS Predicates
      2. IN Predicates
      3. BETWEEN Predicates
      4. LIKE Predicates
    44. Recursive Queries
    45. Regular Expressions
      1. Regular Expressions: MySQL
      2. Regular Expressions: Oracle
      3. Regular Expressions: PostgreSQL
      4. Regular Expressions: SQL Server
    46. Selecting Data
      1. The SELECT Clause
        1. Listing the columns to retrieve
        2. Taking shortcuts with the asterisk
        3. Writing expressions
        4. Specifying result-set column names
        5. Dealing with case and punctuation in names
        6. Using subqueries in a SELECT list
        7. Qualifying column names
      2. ALL and DISTINCT
      3. The FROM Clause
        1. Table aliases in the FROM clause
        2. Subqueries in the FROM clause
        3. Generating tables through the VALUES clause
      4. The WHERE Clause
      5. The GROUP BY Clause
      6. The HAVING Clause
      7. The ORDER BY Clause
    47. String Functions
      1. Searching a String
      2. Replacing Text in a String
      3. Extracting a Substring
      4. Finding the Length of a String
      5. Concatenating Strings
      6. Trimming Unwanted Characters
      7. Changing the Case of a String
    48. Subqueries
      1. Subqueries in the FROM Clause
      2. Subqueries in the WITH Clause
    49. Tables, Creating
      1. Creating a Table: DB2
      2. Creating a Table: MySQL
      3. Creating a Table: Oracle
      4. Creating a Table: PostgreSQL
      5. Creating a Table: SQL Server
    50. Tables, Dropping
    51. Tables, Modifying
      1. Modifying a Table: DB2
      2. Modifying a Table: MySQL
      3. Modifying a Table: Oracle
      4. Modifying a Table: PostgreSQL
      5. Modifying a Table: SQL Server
    52. Transaction Management
      1. Autocommit Mode
      2. Starting a Transaction: DB2
      3. Starting a Transaction: MySQL
      4. Starting a Transaction: Oracle
      5. Starting a Transaction: PostgreSQL
      6. Starting a Transaction: SQL Server
      7. Ending a Transaction
      8. Aborting a Transaction
      9. Aborting to a Savepoint
    53. Union Queries
      1. UNION and UNION ALL
        1. UNION
        2. UNION ALL
      2. ORDER BY in Union Queries
      3. Names and Data Types in a Union
      4. Order of Evaluation
      5. EXCEPT (or MINUS) and EXCEPT ALL
        1. EXCEPT (MINUS in Oracle)
        2. EXCEPT ALL
      6. INTERSECT and INTERSECT ALL
        1. INTERSECT
        2. INTERSECT ALL
    54. Updating Data
      1. Simple Updates
      2. New Values from a Subquery
      3. Updating Views and Subqueries
      4. UPDATE FROM Clause
      5. Returning Updated Data: DB2
      6. Returning Updated Data: Oracle
      7. Returning Updated Data: SQL Server
    55. Window Functions
      1. Defining a Summary Window
      2. Ordering and Ranking Within a Window
      3. Comparing Values Across Rows
      4. Summarizing over a Moving Window
      5. Window Function Evaluation and Placement
  4. Index
  5. About the Author
  6. Copyright