> For the complete documentation index, see [llms.txt](https://vikram-bajaj.gitbook.io/cs-gy-6083-principles-of-database-systems/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://vikram-bajaj.gitbook.io/cs-gy-6083-principles-of-database-systems/sql/intermediate-sql/joins-revisited.md).

# Joins Revisited

* 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

## ![](/files/-M5-0_QjVze3qn3fNAgc)Types of Joins

The cartesian product of two relations ($$r\times 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. &#x20;

   It is denoted by ($$r \bowtie \_C s$$) and is equivalent to $$\sigma\_C (r\times s)$$.
2. **Equijoin**

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

   Ex. $$r \bowtie \_{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. &#x20;

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


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://vikram-bajaj.gitbook.io/cs-gy-6083-principles-of-database-systems/sql/intermediate-sql/joins-revisited.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
