SQL Finish Subqueries, Joins, Distinct, Grouping, and Aggregation




CS157a

Chris Pollett

Nov 6, 2023

Outline

Introduction

Subqueries in FROM Clauses

Joins in SQL

Natural Joins

Outer Joins

Quiz

Which of the following is true?

  1. The datalog rule `T(a,b) \leftarrow R(a),S(b)` could be used to compute a Cartesian product of tables `R` and `S`.
  2. Projection operations in the relational algebra correspond to WHERE clause conditions in SQL.
  3. The query below is an example of a correlated subquery:
    SELECT name
    FROM MovieExec
    WHERE cert# =
        (SELECT producerC#
         FROM Movies
         WHERE title = 'Star Wars' ); 
    

Full-Relation Operations

Eliminating Duplicates

Aggregation in SQL

GROUP BY Clauses

Grouping, Aggregation, and Nulls

Having Clauses