Why SQL?
Since the last edition of SQL Pocket Guide was published, a lot has changed in the data world. The amount of data generated and collected has exploded, and a number of tools and jobs have been created to handle the influx of data. Through all of the changes, SQL has remained an integral part of the data landscape.
Over the past 15 years, I have worked as an engineer, consultant, analyst, and data scientist, and I have used SQL in every one of my roles. Even if my main responsibilities were focused on another tool or skill, I had to know SQL in order to access data at a company.
If there was a programming language award for best supporting actor, SQL would take home the prize.
As new technologies emerge, SQL is still top of mind when it comes to working with data. Cloud-based storage solutions like Amazon Redshift and Google BigQuery require users to write SQL queries to pull data. Distributed data processing frameworks like Hadoop and Spark have sidekicks Hive and Spark SQL, respectively, which provide SQL-like interfaces for users to analyze data.
SQL has been around for almost five decades, and it is not going away anytime soon. It is one of the oldest programming languages still being used widely today, and I am excited to share the latest and greatest with you in this book.
Goals of This Book
There are many existing SQL books out there, ranging from ones that teach beginners how to code in SQL to detailed technical specifications for database administrators. This book is not intended to cover all SQL concepts in depth, but rather to be a simple reference for when:
Youve forgotten some SQL syntax and need to look it up quickly
Youve come across a slightly different set of database tools at a new job and need to look up the nuanced differences
Youve been focusing on another coding language for a while and need a quick refresher on how SQL works
If SQL plays a large supporting role in your job, then this is the perfect pocket guide for you.
Updates to the Fourth Edition
The third edition of the SQL Pocket Guide by Jonathan Gennick was published in 2010, and it was well received by readers. Ive made the following updates to the fourth edition:
The syntax has been updated for Microsoft SQL Server, MySQL, Oracle Database, and PostgreSQL. IBMs Db2 has been removed due to its decrease in popularity, and SQLite has been added due to its increase in popularity.
The third edition of this book was organized alphabetically. Ive rearranged the sections in the fourth edition so that similar concepts are grouped together. There is still an index at the end of this book that lists concepts alphabetically .
Due to the number of data analysts and data scientists who are now using SQL in their jobs, Ive added sections on how to use SQL with Python and R (popular open source programming languages), as well as a SQL crash course for those who need a quick refresher.
Frequently Asked (SQL) Questions
The last chapter of this book is called "" and it includes frequently asked questions by SQL beginners or those who havent used SQL in a while.
Its a good place to start if you dont remember the exact keyword or concept that youre looking for. Example questions include:
How do I find the rows containing duplicate values?
How do I select rows with the max value for another column?
How do I concatenate text from multiple fields into a single field?
Navigating This Book
This book is organized into three sections.
I. Basic Concepts
Chapters introduce basic keywords, concepts, and tools for writing SQL code.
breaks down each clause of a SQL query.
II. Database Objects, Data Types, and Functions
lists common ways to create and modify objects within a database.
lists common data types that are used in SQL.
lists common operators and functions in SQL.
III. Advanced Concepts
Chapters explain advanced querying concepts including joins, case statements, window functions, etc.
walks through solutions to some of the most commonly searched for SQL questions.
Conventions Used in This Book
The following typographical conventions are used in this book:
ItalicIndicates new terms, URLs, email addresses, filenames, and file extensions.
Constant width
Used for program listings, as well as within paragraphs to refer to program elements such as variable or function names, databases, data types, environment variables, statements, and keywords.
Constant width bold
Shows commands or other text that should be typed literally by the user, or values determined by context.
Tip
This element signifies a tip or suggestion.
Note
This element signifies a general note.
Warning
This element indicates a warning or caution.
Using Code Examples
If you have a technical question or a problem using the code examples, please send email to .