7. Subqueries, Cases, and Views

Overview

In this chapter, we will look at some techniques that will help us add logic to our existing queries using CASE statements. We will also query data present in multiple tables using subqueries. We will also create views using queries that allows us the flexibility to create a temporary table to run queries on.

Introduction

In the previous chapter, we saw how the various types of SQL joins can connect multiple tables in a single SELECT query. This powerful technique gives us fine-grained control over the data that our SQL queries return. However, SQL offers much more. In this chapter, we'll use the PACKT_ONLINE_SHOP database to see how subqueries, CASE statements, and views boost the flexibility and ...

Get The SQL Workshop now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.