Skip to main content
Top

2017 | Book

MariaDB and MySQL Common Table Expressions and Window Functions Revealed

insite
SEARCH

About this book

Walk away from old-fashioned and cumbersome query approaches and answer your business intelligence questions through simple and powerful queries built on common table expressions (CTEs) and window functions. These new features in MariaDB and MySQL help you to write queries without having to wade through a quagmire of brittle self-joins and other crazy techniques from the past. Your queries will generate correct results, be more readable and less brittle in the face of unexpected data, and you’ll be able to adapt them quickly in the face of changing business requirements.
MariaDB and MySQL Common Table Expressions and Window Functions Revealed introduces and explains CTEs and window functions, newly available in MariaDB 10.2 and MySQL 8.0, and helps you understand why and how every MariaDB and MySQL database programmer should learn and apply these features in their daily work. CTEs and especially window functions enable easy solutions to many query challenges that in prior releases have been difficult and sometimes impossible to surmount. Mastering these features opens the door to query solutions that are more robust, execute faster, and are easier to maintain over time than prior solutions using older techniques. The book:Takes you step-by-step through the workings of common table expressions and window functions
Provides easy-to-follow examples of the new syntaxHelps you answer business questions faster and easier than everWhat You'll Learn
Answer business questions using simple queries that don’t break in the face of unexpected data
Avoid writing queries that are a difficult-to-maintain quagmire of self-joins and nested subqueriesRecognize situations that call for window functions, and learn when to use these features
Reduce the need for performance-robbing self-joins
Simplify and speed the execution of analytical queriesCreate queries that finish in seconds instead of hoursWho This Book Is For
Database administrators and application developers who want to quickly get up to speed on important features in MariaDB and MySQL for writing business intelligence queries. Any developer writing SQL against MariaDB and MySQL databases will benefit tremendously from the knowledge and techniques this book provides.

Table of Contents

Frontmatter

Common Table Expressions

Frontmatter
Chapter 1. Basics of Common Table Expressions
Abstract
Common Table Expressions (CTEs) are one of the new SQL features introduced in MariaDB 10.2 and MySQL 8.0. This chapter will introduce CTEs, describe the two types, and explain the basic syntax. CTEs are named temporary result sets that only last for the duration of the query they are in. In some respects, they are similar to derived tables, but they are more powerful.
Daniel Bartholomew
Chapter 2. Non-recursive Common Table Expressions
Abstract
You already got a taste of non-recursive CTEs in the previous chapter. This chapter will expand upon the previous examples and show more of the things you can do with non-recursive CTEs. In this chapter, we’ll cover some common uses of CTEs and finish with how to convert existing queries that use subqueries into queries that use CTEs.
Daniel Bartholomew
Chapter 3. Recursive Common Table Expressions
Abstract
Implementations of this standard started appearing in various databases, such as Oracle and SQL Server, starting around 2007, with MariaDB and MySQL finally catching up and getting them about ten years after that.
Daniel Bartholomew

Window Functions

Frontmatter
Chapter 4. Basics of Window Functions
Abstract
The first three chapters have all been about CTEs. For this and the next two chapters, we are switching gears and will be exploring Window Functions. Like CTEs, these were introduced in MariaDB 10.2 and MySQL 8.0 (as of 8.0.2 DMR).
Daniel Bartholomew
Chapter 5. Recognizing Opportunities for Window Functions
Abstract
The previous chapter was an overview of what Window Functions are, with details on the syntax. It’s time to put that knowledge into practice. This chapter expands upon that with some simple yet practical examples that illustrate some of the types of problems Window Functions are good at solving. We’ll cover organizing results, maintaining running totals, and ranking results.
Daniel Bartholomew
Chapter 6. Window Functions in Practice
Abstract
This chapter contains several examples that demonstrate using Window Functions in the real world.
Daniel Bartholomew
Chapter 7. Combining Window Functions and CTEs
Abstract
Window Functions and CTEs are great in isolation, but they can also be very useful together. This chapter will walk through some examples that demonstrate how Window Functions and CTEs can be used together. We’ll start with a simple averaging of rainfall data, then move on to how to use CTEs and Window Functions together to fix a common schema issue. Lastly, we’ll use them to do some deeper analysis on our rainfall data to find gaps and islands in our data set.
Daniel Bartholomew
Backmatter
Metadata
Title
MariaDB and MySQL Common Table Expressions and Window Functions Revealed
Author
Daniel Bartholomew
Copyright Year
2017
Publisher
Apress
Electronic ISBN
978-1-4842-3120-3
Print ISBN
978-1-4842-3119-7
DOI
https://doi.org/10.1007/978-1-4842-3120-3

Premium Partner