CS-GY 6083: Principles of Database Systems
main
main
  • Introduction
  • DBMS Basics
    • Introduction to DBMS
    • Why use a DBMS instead of a File System?
    • Levels of Abstraction
    • Instances and Schemas
  • Data Models
    • Introduction to Data Models
    • Database Languages
    • Database Design
  • DBMS Internals
    • Introduction to DBMS Internals
    • Storage Manager
    • Query Processor
    • Transaction Management
    • Database Users
    • Database Architecture
  • DBMS History
  • Some Popular Database Systems
  • OLTP, OLAP, and Data Mining
  • Databases vs. Information Retrieval
  • The Entity-Relationship Model - Details
    • Introduction
    • Cardinality Constraints
    • ER Diagram Components
    • ER Diagram to Relational Schema
    • Design Issues
  • The Relational Model - Details
    • Relations
    • Keys
    • Relational Query Languages
      • Relational Algebra
      • Relational Calculus
      • Relative Expressive Power
    • Relational Operators
  • SQL
    • Introduction to SQL
    • Domain Types in SQL
    • DDL Commands
      • Creating a Table
      • Alter and Drop
    • DML Commands
      • Basic Query Structure
      • Select
      • From
      • Where
      • Joins
      • Rename
      • String Operations
      • Ordering
      • Set Operations
      • Group By and Having
      • Nested Subqueries
      • Test for Empty Relations
      • Test for Duplicate Tuples
      • Derived Relations
      • With
      • Database Modification
    • Intermediate SQL
      • Joins Revisited
      • Views
      • Transactions
      • Integrity Constraints
      • More SQL Data Types and Schemas
        • Other Features
      • Authorization
    • Advanced SQL
      • Accessing SQL From a Programming Language
        • ODBC and JDBC
        • Embedded SQL
        • PHP
        • Some Security Issues
      • Accessing Metadata
      • Text Operations
        • Like
        • Contains
      • Cursors
      • Functions and Procedures
        • Procedural Constructs
        • External Language Routines
      • Triggers
      • Ranking
      • Windowing
      • OLAP
Powered by GitBook
On this page

Was this helpful?

  1. SQL
  2. Intermediate SQL

Joins Revisited

PreviousIntermediate SQLNextViews

Last updated 4 years ago

Was this helpful?

  • Join operations take two relations and return as a result another relation

  • A join operation is a Cartesian product which requires that tuples in the two relations match (under some condition). It also specifies the attributes that are present in the result of the join

  • The join operations are typically used as subquery expressions in the from clause

  • Join condition – defines which tuples in the two relations match, and what attributes are present in the result of the join

  • Join type – defines how tuples in each relation that do not match any tuple in the other relation (based on the join condition) are treated

Types of Joins

The cartesian product of two relations (r×sr\times sr×s) will return all possible combinations of the tuples in r and s.

The cartesian product is the first step in joining two relations. A join is simply a catresian product followed by selection/projection.

We have 3 kinds of joins:

  1. Conditional Join

    This is the same as performing a cartesian product based on a condition.

    It is denoted by (r⋈Csr \bowtie _C sr⋈C​s) and is equivalent to σC(r×s)\sigma_C (r\times s)σC​(r×s).

  2. Equijoin

    The result of this join will only contain records having equal values for the common field.

    Ex. r⋈r.id=s.idsr \bowtie _{r.id=s.id} sr⋈r.id=s.id​s

  3. Natural Join

    This is an equijoin considering all fields common between r and s. These fields do not have to be mentioned in a condition.

    If there are no common fields, natural join will be the same as a cross product.